<?php
/**
 * 人才顾问控制器方法
 * @time 2020/12/15 17:25
 */

namespace Home\Controller;

use Api\Model\GuwenLevelModel;
use Api\Model\GuwenModel;
use Api\Model\JobsInfoModel;
use Common\Model\ExplainModel;
use Common\Model\JobsModel;
use Common\Controller\PcApiController;
use Common\Model\ArticleCategoryModel;
use Common\Model\CategoryDistrictModel;
use Common\Model\CategoryPinModel;
use Common\qscmstag\school_election_listTag;
use crmeb\services\JsonService as Json;

class PcJobsinfoController extends PcApiController
{
    protected $company_profile = false;
    private $dbconfig = array();

    /**
     * 文件指针
     * @var resource
     */
    private $fp;
    /**
     * 备份文件信息 part - 卷号，name - 文件名
     * @var array
     */
    private $file;
    /**
     * 当前打开文件大小
     * @var integer
     */
    private $size = 0;


    /**
     * 备份配置
     * @var integer
     */
    protected $config = array(
        'path' => './Data/',
        //数据库备份路径
        'part' => 20971520,
        //数据库备份卷大小
        'compress' => 0,
        //数据库备份文件是否启用压缩 0不压缩 1 压缩
        'level' => 9,
    );
    public function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 写入SQL语句
     *
     * @param string $sql 要写入的SQL语句
     * @return boolean     true - 写入成功，false - 写入失败！
     */
    private function write(string $sql)
    {
        $size = strlen($sql);
        //由于压缩原因，无法计算出压缩后的长度，这里假设压缩率为50%，
        //一般情况压缩率都会高于50%；
        $size = $this->config['compress'] ? $size / 2 : $size;
        $this->open($size);
        return $this->config['compress'] ? @gzwrite($this->fp, $sql) : @fwrite($this->fp, $sql);
    }

    /**
     * 打开一个卷，用于写入数据
     *
     * @param integer $size 写入数据的大小
     */
    private function open(int $size)
    {
      //  var_dump($this->fp);die;
        if ($this->fp) {
            $this->size += $size;
            if ($this->size > $this->config['part']) {
                $this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp);
                $this->fp = null;
                $this->file['part']++;
                session('backup_file', $this->file);
                $this->Backup_Init();
            }
        } else {
            $backuppath = $this->config['path'];
            $filename = "{$backuppath}{$this->file['name']}-{$this->file['part']}.sql";
            if ($this->config['compress']) {
                $filename = "{$filename}.gz";
                $this->fp = @gzopen($filename, "a{$this->config['level']}");
            } else {
                $this->fp = @fopen($filename, 'a');
            }
            $this->size = filesize($filename) + $size;
        }
    }


    public function backup(string $table, int $start)
    {
       // $db = self::connect();
        // 备份表结构
        if (0 == $start) {
            $result = M()->query("SHOW CREATE TABLE `{$table}`");
           // var_dump($result);die;
            $sql = "\n";
            $sql .= "-- -----------------------------\n";
            $sql .= "-- Table structure for `{$table}`\n";
            $sql .= "-- -----------------------------\n";
            $sql .= "DROP TABLE IF EXISTS `{$table}`;\n";
            $sql .= trim($result[0]['Create Table']) . ";\n\n";
            if (false === $this->write($sql)) {
                return false;
            }
        }
        //数据总数
        $result = M()->query("SELECT COUNT(*) AS count FROM `{$table}`");
        $count = $result['0']['count'];
        //备份表数据
        if ($count) {
            //写入数据注释
            if (0 == $start) {
                $sql = "-- -----------------------------\n";
                $sql .= "-- Records of `{$table}`\n";
                $sql .= "-- -----------------------------\n";
                $this->write($sql);
            }
            //备份数据记录
            $result =M()->query("SELECT * FROM `{$table}` LIMIT $start, 1000");
            foreach ($result as $row) {
                $row = array_map('addslashes', $row);
                $sql = "INSERT INTO `{$table}` VALUES ('" . str_replace(array("\r", "\n"), array('\\r', '\\n'), implode("', '", $row)) . "');\n";
                if (false === $this->write($sql)) {
                    return false;
                }
            }
            //还有更多数据
            if ($count > $start + 1000) {
                //return array($start + 1000, $count);
                return $this->backup($table, $start + 1000);
            }
        }
        //备份下一表
        return 0;
    }


    /**
     * 写入初始数据
     *
     * @return boolean true - 写入成功，false - 写入失败
     */
    public function Backup_Init()
    {
        $sql = "-- -----------------------------\n";
        $sql .= "-- Think MySQL Data Transfer \n";
        $sql .= "-- \n";
        $sql .= "-- Host     : " . $this->dbconfig['hostname'] . "\n";
        $sql .= "-- Port     : " . $this->dbconfig['hostport'] . "\n";
        $sql .= "-- Database : " . $this->dbconfig['database'] . "\n";
        $sql .= "-- \n";
        $sql .= "-- Part : #{$this->file['part']}\n";
        $sql .= "-- Date : " . date("Y-m-d H:i:s") . "\n";
        $sql .= "-- -----------------------------\n\n";
        $sql .= "SET FOREIGN_KEY_CHECKS = 0;\n\n";
        return $this->write($sql);
    }

 public function bb()
 {

     $tables = ['qs_members'];
     //$db = $this->DB;
     $data = '';
     foreach ($tables as $t) {
         $res = $this->backup($t, 0);
         if ($res == false && $res != 0) {
             $data .= $t . '|';
         }
     }
    $this->ajaxReturn(1,'',$data);

 }



    /**
     * 注销人才顾问
     */
    public function guwen_out()
    {
        $user_info = $this->userinfo;
        $res = JobsInfoModel::out_gu_wen($user_info);
        if ($res) {
            $this->ajaxReturn(0, '成功', '');
        }
        $this->ajaxReturn(1, '失败，请重试', '');
    }

    /**
     * 我的人才库
     */
    public function my_rencai()
    {
        $cate_id = I('cate_id', 0);
        $key = I('key', '');
        $res = JobsInfoModel::get_rencai($this->userinfo['uid'], I('page', 1), I('page_size', 10), $cate_id, $key);
        $this->ajaxReturn(0, '', $res);
        // var_dump($res);die;
    }

    /**
     * 顾问搜索人才
     */
    public function rencaiSearch()
    {
        $mobile = I('post.mobile', '', 'trim,badword');
        $page   = I('post.page', 1, 'intval');
        $pageSize= 10;
        if (!empty($mobile) && !fieldRegex($mobile,'mobile')) $this->ajaxReturn(1, '手机格式错误');
        if ($this->userinfo['utype'] <> 3) $this->ajaxReturn(1, '当前用户类型，不能搜索人才');

        $result1    = M('GuwenUser')->where(['guwen_id'=>$this->userinfo['uid']])->getField('uid',true);
        $result2    = M('GuwenUserTmp')->where(['guwen_id'=>$this->userinfo['uid']])->getField('uid',true);
        $guwen1     = is_array($result1) ? $result1 : array();
        $guwen2     = is_array($result2) ? $result2 : array();

        $guwen  = array_merge($guwen1,$guwen2);
        $field  = 'm.uid as uid, r.fullname as fullname, r.sex as sex, r.sex_cn as sex_cn, m.reg_time as reg_time, r.jobs_id as jobs_id, r.trade as trade, r.trade_cn as trade_cn, r.current as current, r.current_cn as current_cn';

        $where  = ['m.utype' => 2];
        if($guwen){
            $where['m.uid'] = ['not in', $guwen];
        }
        if(!empty($mobile)){
            $where['m.mobile'] = $mobile;
            $count      = M('Resume as r')->join('left join qs_members as m on m.uid=r.uid')->where($where)->count();
            $totalPage  = ceil($count / $pageSize);
            $result     = M('Resume as r')->field($field)->join('left join qs_members as m on m.uid=r.uid')->where($where)->page($page, $pageSize)->select();
        }else {
            $count      = M('Resume as r')->join('left join qs_members as m on m.uid=r.uid')->where($where)->count();
            $totalPage  = ceil($count / $pageSize);
            $result     = M('Resume as r')->field($field)->join('left join qs_members as m on m.uid=r.uid')->where($where)->order('addtime desc')->page($page, $pageSize)->select();
        }

        $data   = [];
        foreach($result as $value) {
            $jobs = explode(',', $value['jobs_id']);
            $jobsName = [];
            foreach ($jobs as $val) {
                $jobsName[] = D('CategoryJobs')->getJobsName($val);
            }

            $data[] = [
                'uid'       => $value['uid'],
                'fullname'  => $value['fullname'],
                'sex'       => $value['sex'],      //性别
                'sex_cn'    => $value['sex_cn'],   //性别明文
                'avatar'    => avatar($value['uid']),
                'reg_time'  => date('Y-m-d', $value['reg_time']),
                'jobs_id'   => $value['jobs_id'],//职位类别ID
                'jobs_id_cn'=> $jobsName,//职位类别明文
                'trade'     => $value['trade'],//工程类别
                'trade_cn'  => explode(',', $value['trade_cn']),//工程类别明文
                'current'   => $value['current'],//求职状态
                'current_cn'=> $value['current_cn'],//求职状态明文
            ];
        }
        $this->ajaxReturn(0, '', ['totalPage'=>$totalPage, 'data'=>$data]);
        // var_dump($res);die;
    }

    /**
     * 顾问邀请人才
     */
    public function guwenInvite(){
        $uid = I('post.uid', 0, 'intval');
        if(!$uid) $this->ajaxReturn(1,'邀请的人才ID不存在');

        $result = M('Resume as r')->field('m.uid')->join('left join qs_members as m on m.uid=r.uid')->where(['m.utype'=>2, 'm.uid'=>$uid])->find();
        if (!$result) $this->ajaxReturn(1, '邀请的人才不存在');

        $gut    = M("GuwenUserTmp")->where(['guwen_id'=>$this->userinfo['uid'], 'uid'=>$uid])->find();
        if($gut) $this->ajaxReturn(1, '你已经邀请过该人才，请勿重复邀请');

        $gut    = M("GuwenUser")->where(['guwen_id'=>$this->userinfo['uid'], 'uid'=>$uid])->find();
        if($gut){
            if($gut['status']==1)
                $this->ajaxReturn(1, '当前人才已经拒绝了你');
            else
                $this->ajaxReturn(1, '当前人才已经在你的人才库');
        }

        if(M("GuwenUserTmp")->add(['guwen_id'=>$this->userinfo['uid'], 'uid'=>$uid, 'add_time'=>time()]))
            $this->ajaxReturn(0, '邀请成功');
        else
            $this->ajaxReturn(1, '邀请失败');
    }


    /**
     * 简历列表
     */
    public function resume_list()
    {
        $res = JobsInfoModel::get_resume_list();
        $this->ajaxReturn(0, '', $res);
    }

    /**
     * 简历详情
     */

    public function resume_detail()
    {
        !I('id') && $this->ajaxReturn(1, '简历不存在');
        $info = JobsInfoModel::resume_detail();
        $this->ajaxReturn(0, '', $info);
    }
/**
 * 下载用户的简历 查询订单修改状态
 */
   public function sel_down_user_order($uid)
   {
      $ids=M('gu_wen_jie_dan_order')->join('as g left join qs_guwen_tui_jian_rusume as gt on g.id=gt.order_id and gt.resume_uid ='.$uid)->where(['g.order_status'=>6])->getField('g.id,gt.order_id',true);
        if($ids){
            return M('gu_wen_jie_dan_order')->where(['id'=>['in',$ids]])->setField('order_status',2);
        }
       return false;
   }

    /**
     * 简历下载
     */
    public function resume_download()
    {
        $rid = I('rid');

        if (!$rid) {
            $this->ajaxReturn(1, '请选择简历！');
        }

        //用户信息
        $user_info=M('resume')->where(['id'=>$rid])->find();
        if(empty($user_info)){
            $this->ajaxReturn(1,'简历不存在');
        }

        $info=$this->check_down_resume($user_info['uid'],C('visitor.uid'));
        // var_dump($info);die;
        if ($info)
        {
            $this->ajaxReturn(1,'您已经下载过此简历了');
            // return array('state'=>0,'msg'=>'您已经下载过此简历了');
        }
        $rid = is_array($rid) ? $rid : explode(",", $rid);
        $down_type=I('down_type',1);//下载类型 1 订单  2 搜索
        $tui_jian_id=0;
        if($down_type==1){
           $tui_jian_id=I('tui_jian_id',0);
           if(empty($tui_jian_id)){
               $this->ajaxReturn(1,'参数错误');
           }
        }
        if (IS_POST) {
            $payment_name = I('payment_name', '', 'trim');
//            if(empty($payment_name)){
//                $this->ajaxReturn(1,'支付方式错误');
//            }
            $jl_down_money = M('config')->where(['name' => 'jl_download_money'])->getField('value');
            // todo 如果是微信或者支付宝支付，调起支付接口
            if ($payment_name) {
                if ($payment_name == 'gcb') {
                    //判断当前工程币的数量
                    $gcb_info = D('MembersSetgcb')->get_user_setmeal(C('visitor.uid'));
                    $sheng_gcb = $gcb_info['all_num'] - $gcb_info['use_num'];

                    if ($sheng_gcb >= $jl_down_money) {

                        //下载简历
                        $addarr['rid'] = $rid;
                        $addarr['down_type'] = $down_type;
                        $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号
                        $params['resume_id']    = $rid[0];
                        $params['type']         = 'resume_download';
                        $params['down_type']=$down_type;
                        $params['tui_jian_id']=$tui_jian_id;
                        $params = serialize($params);
                        $order_insert_id = D('Order')->add_order_copy(C('visitor'), $oid, 14, $jl_down_money, $jl_down_money, 0, '下载简历', $payment_name, '工程币支付', '下载简历', time(), 1, 0, 0, time(), $params, '', '', 0, 0, 0, $rid[0]);
                        /* 会员日志 */
                        write_members_log(C('visitor'), 'order', '创建增值服务订单（订单号：' . $oid . '），支付方式：工程币支付', false, array('order_id' => $order_insert_id));
                        $time = time();
                        $order = D('Order')->where(array('id' => $order_insert_id))->find();
                        $this->ajaxReturn(0,'ok',$order_insert_id);
//                        $res = D('Order')->order_paid($order['oid'], $time);
//                        if ($res) {
//                            //先修改这个用户的推荐表的订单状态 /0 未接单 1. 已接单 6 待处理 2 处理中 3已完成 4 已取消 5 意向
//                            $this->sel_down_user_order($user_info['uid']);
//                            $this->ajaxReturn(0, '下载成功！');
//
//                        } else {
//                            $this->ajaxReturn(1, '下载支付出错');
//                        }

                    } else {
                        $this->ajaxReturn(1, '您的工程币不足', '');
                    }
                } elseif ($payment_name == 'remittance') {
                    //线下转账
                    $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号
                    $params['resume_id']    = $rid[0];
                    $params['type']         = 'resume_download';
                    $params['down_type']=$down_type;
                    $params['tui_jian_id']=$tui_jian_id;
                    $params = serialize($params);
                    $order_insert_id = D('Order')->add_order_copy(C('visitor'), $oid, 14, $jl_down_money, $jl_down_money, 0, '下载简历', $payment_name, '工程币支付', '下载简历', time(), 1, 0, 0, time(), $params, '', '', 0, 0, 0, $rid[0]);


                    /* 会员日志 */
                    write_members_log(C('visitor'), 'order', '创建增值服务订单（订单号：' . $oid . '），支付方式：工程币支付', false, array('order_id' => $order_insert_id));
                    if ($order_insert_id) {
                        $this->ajaxReturn(0, '成功，请等待管理员审核');
                    }
                } else {
                    //微信
                    $is_deductible  = I('request.is_deductible', 0, 'intval');
                    $deductible     = I('request.deductible', 0, 'intval');

//                    $wxcode         = I('post.wxcode','','trim,badword');
//                    if (empty($wxcode)) $this->ajaxReturn(1, '微信wxcode不能为空');
//
//                    $openId         = wxOpenId($wxcode, $this->userinfo['uid']);
//                    if (!empty($openId['status'])) $this->ajaxReturn(1, '微信openId获取失败');

                    $params['resume_id']    = $rid[0];
                    $params['type']         = 'resume_download';
                    $params['down_type']    = $down_type;
                    $params['tui_jian_id']=$tui_jian_id;
                    $params['openid']       = !empty($openId['data']) ? $openId['data'] : '';
                    $params = serialize($params);

                    $htype_cn   = D('Order')->order_type[14];
                    $re         = call_web_cash_pay($htype_cn, 14, $openId['data'], 'wxpay', C('qscms_jl_download_money'), $is_deductible, $deductible, $params);
                    if($re['status']==1) $this->ajaxReturn(1, $re['msg']);
                    $url=$re['data']['data'];
                    $str=$this->indexBase64($url);
                    $re['data']['img_base']=$str;
                    $this->ajaxReturn(0, 'ok', $re['data']);
                }
            } else {
                //如果有简历下载次数则直接下载
                //查询套餐信息
                $tao_can = D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));
                //                var_dump($tao_can);
                //var_dump($tao_can['jl_down_num']-$tao_can['jl_yi_down_num']);
                if ($tao_can) {
                    if (!($tao_can['jl_down_num'] - $tao_can['jl_yi_down_num'])) {
                        $this->ajaxReturn(1, '您已无剩余下载次数！');
                    }
                } else {
                    //判断下载简历次数 是否大于3
                    $count = D('CompanyDownResume')->get_down_count(C('visitor.uid'));
                    if ($count > 3) {
                        $this->ajaxReturn(1, '您已无剩余免费下载次数！');
                    }
                }
                $addarr['rid'] = $rid;
                $addarr['down_type'] = $down_type;
                $params['resume_id']    = $rid[0];
                $params['tui_jian_id']=$tui_jian_id;
                $params['type']         = 'resume_download';
                $params['down_type']=$down_type;
                $params = serialize($params);
                $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号

                $order_insert_id = D('Order')->add_order_copy(C('visitor'), $oid, 14, $jl_down_money, $jl_down_money, 0, '下载简历', 'use_taocan', '套餐次数支付', '下载简历', time(), 1, 0, 0, time(), $params, '', '', 0, 0, 0, $rid[0]);
                /* 会员日志 */
                write_members_log(C('visitor'), 'order', '创建下载简历订单（订单号：' . $oid . '），支付方式：套餐次数支付', false, array('order_id' => $order_insert_id));
                $time = time();
                $order = D('Order')->where(array('id' => $order_insert_id))->find();
                $res = D('Order')->order_paid($order['oid'], $time);

                if ($res===true || $res['state']!=0) {
//                    $r = D('CompanyDownResume')->add_down_resume($addarr, C('visitor'));
//                    if ($r['state'] == 1) {
//                        //使用次数加一
                    //判断是否有免费次数
                    $count = D('CompanyDownResume')->get_down_count(C('visitor.uid'));
                    if ($count > 3) {
                        M('members_settaocan')->where([
                            'uid' => C('visitor.uid')
                        ])->setInc('jl_yi_down_num', 1);
                    }
//                        //先修改这个用户的推荐表的订单状态
//                        //先修改这个用户的推荐表的订单状态 /0 未接单 1. 已接单 6 待处理 2 处理中 3已完成 4 已取消 5 意向 7 未下载
                      $this->sel_down_user_order($user_info['uid']);
                      $res = D('Resume')->save_as_doc_word($rid, '', C('visitor'), 1,1);
                   //   var_dump($res);die;
                      $site_url = M('config')->where(['name' => 'site_domain'])->find();
                      $url = $site_url['value'] . $res['path'] . $res['name'];
                    //  var_dump($res);
                      $data['url']=$url;
                      $this->ajaxReturn(0, '下载成功！',$data);

//                    } else {
//                        $this->ajaxReturn(1, $r['msg']);
//                    }
                } else {
                    D('Order')->where(array('id' => $order_insert_id))->delete();
                    $this->ajaxReturn(1, $res['msg']);
                }

            }
        }
    }


    /**
     * 启动现金支付
     */
    protected function _call_cash_pay($increment_info, $order_pay_type, $payment_name = '', $amount = '0.0', $is_deductible, $deductible = 0, $description = '', $params = '', $points = 0, $stemeal = 0, $discount = '')
    {
        $paymenttpye = D('Payment')->get_payment_info($payment_name);
        if (!$paymenttpye) $this->notice("支付方式错误！");
        if ($this->my_points < $deductible) {
            $this->notice(C('qscms_points_byname') . '不足，请使用其他方式支付！');
        }
        if ($is_deductible == 0) {
            $deductible = 0;
        }
        if ($deductible > 0) {
            $m_amount = $amount - floatval($deductible / C('qscms_payment_rate'));
        } else {
            $m_amount = $amount;
        }

        $paysetarr['ordtotal_fee'] = $m_amount;
        if ($description == '') {
            $description = '购买服务：' . $increment_info['name'];
        }
        $description .= ';' . $paymenttpye['byname'] . $paysetarr['ordtotal_fee'] . '元';

        if ($deductible > 0) {
            $description .= ';' . C('qscms_points_byname') . '支付：' . $deductible . C('qscms_points_byname');
        }
        $paysetarr['oid'] = strtoupper(substr($paymenttpye['typename'], 0, 1)) . "-" . date('ymd', time()) . "-" . date('His', time()); //订单号
        $insert_id = D('Order')->add_order(C('visitor'), $paysetarr['oid'], $order_pay_type, $amount, $paysetarr['ordtotal_fee'], $deductible, $increment_info['name'], $payment_name, $paymenttpye['byname'], $description, $this->timestamp, 1, $points, $stemeal, 0, $params, $discount);
        if ($deductible > 0 && $is_deductible == 1) {
            $log_payment = $paymenttpye['byname'] . '+' . C('qscms_points_byname') . '抵扣';
        } else {
            $log_payment = $paymenttpye['byname'];
        }
        write_members_log(C('visitor'), 'order', '创建增值服务订单（订单号：' . $paysetarr['oid'] . '），支付方式：' . $log_payment, false, array('order_id' => $insert_id));
        if ($payment_name == 'remittance') {
            $this->redirect('order_detail', array('id' => $insert_id));
            exit;
        }
        $paysetarr['payFrom'] = 'pc';
        $paysetarr['type'] = $payment_name;
        $paysetarr['ordsubject'] = $increment_info['name'];
        $paysetarr['ordbody'] = $increment_info['name'];
        $r = D('Payment')->pay($paysetarr);
        if (!$r['state']) $this->ajaxReturn(0, $r['msg']);
        if ($payment_name == 'wxpay') {
            fopen(QSCMS_DATA_PATH . 'wxpay/' . $paysetarr['oid'] . '.tmp', "w") or die("无法打开缓存文件!");
            $_SESSION['wxpay_no'] = $paysetarr['oid'];
            $this->ajaxReturn(1, '回调成功', C('qscms_site_dir') . 'index.php?m=Home&c=Qrcode&a=index&url=' . $r['data']);
        }
    }


    /**
     * 获取工程币套餐
     */

    public function get_gcb_list()
    {
        $list = JobsInfoModel::get_gcb_list();
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * 获取发布套餐
     */

    public function get_taocan_list()
    {
        $list = JobsInfoModel::get_taocan_list();
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * 购买东西
     */


    public function buy_something()
    {
        $type = I('type', 1);

    }

    /**
     * 基础套餐支付
     */
    public function setmeal_add_save()
    {
        $type = I('type', 1);//1 套餐   15 工程币
        if (!in_array($type, [1, 15])) {
            $this->ajaxReturn(1, '类型错误');
        }
        $htype_cn   = D('Order')->order_type[$type];
        $setmeal_id = I('project_id', 0, 'intval');
        if ($type == 1) {
            $info = M('settaocan')->where(['id' => $setmeal_id])->find();
            if (empty($info)) {
                $this->ajaxReturn(1, '套餐已过期');
            }
        } else {
            $info = M('setgcb')->where(['id' => $setmeal_id])->find();
            if (empty($info)) {
                $this->ajaxReturn(1, '套餐已过期');
            }
            $info['setmeal_name'] = $info['name'];
            $info['expense'] = $info['price'];
        }

        $payment_name = I('payment_name', 'remittance');

        $setmeal_info = $info;//D('Setmeal')->get_setmeal_one($setmeal_id);

     //   var_dump($setmeal_info);die;
        if($info['price_rate']>0){
            $amount = number_format($setmeal_info['expense']*$info['price_rate']/100,2,'.','');
        }else{
            $amount=$setmeal_info['expense'];
        }

        if ($amount >= 6000 && !in_array($payment_name,['remittance','gcb'])) {
            $this->ajaxReturn(1, "高于6000请线下付款！");
        }
        // $payment_name='wxpay';
        $paymenttpye = D('Payment')->get_payment_info($payment_name);
        if($payment_name!='gcb'){
            if (!$paymenttpye) $this->ajaxReturn(1, "支付方式错误！");
        }
       // var_dump($amount);;die;
        $paysetarr['ordtotal_fee'] = $amount;
        $description = '购买服务：' . $setmeal_info['setmeal_name'] . ';' . $paymenttpye['byname'] . $paysetarr['ordtotal_fee'];

        if ($payment_name == 'remittance') {
            $paysetarr['oid'] = strtoupper(substr($paymenttpye['typename'], 0, 1)) . "-" . date('ymd', time()) . "-" . date('His', time()); //订单号
            $insert_id = D('Order')->add_order(C('visitor'), $paysetarr['oid'], $type, $amount, $amount, 0, $setmeal_info['setmeal_name'], $payment_name, $paymenttpye['byname'], $description, time(), 1, 0, $setmeal_id, '', '', 0, '', 0, 0);
            write_members_log(C('visitor'), 'order', '创建套餐订单（订单号：' . $paysetarr['oid'] . '），支付方式：⭐转账', false, array('order_id' => $insert_id));

            $this->ajaxReturn(0, '成功，请等待管理员审核',$insert_id);
        }elseif ($payment_name=='gcb'){
                   if($type!=1){
                       $this->ajaxReturn(1,'支付类型错误');
                   }
                $gcb_info = D('MembersSetgcb')->get_user_setmeal(C('visitor.uid'));
                if (empty($gcb_info)) {
                    $this->ajaxReturn(1, '您目前没有工程币套餐');
                }
                if ($gcb_info['all_num'] - $gcb_info['use_num'] < $amount) {
                    $this->ajaxReturn(1, '您的工程币余额不足');
                }
                //生成一个订单
                    $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号

                    $insert_id = D('Order')->add_order(C('visitor'), $oid, 1, $amount, $amount, 0,$setmeal_info['setmeal_name'], 'gcb', '工程币支付', $description, time(), 1, 0, $setmeal_id, time(), '', '', '', 0, 0);

                    write_members_log(C('visitor'), 'order', '创建套餐订单（订单号：' . $paysetarr['oid'] . '），支付方式：工程币支付', false, array('order_id' => $insert_id));
                    $this->ajaxReturn(0, '操作成功', $insert_id);
//                }
        }else {
            //微信
//            $wxcode = I('post.wxcode','','trim,badword');
//            if (empty($wxcode)) $this->ajaxReturn(1, '微信wxcode不能为空');
//
//            $openId = wxOpenId($wxcode, $this->userinfo['uid']);
//            if (!empty($openId['status'])) $this->ajaxReturn(1, '微信openId获取失败');

            $params             = [
                'resume_id' => $this->isResume()['id'],
                'amount'    => $paysetarr['ordtotal_fee'],
                'openid'    => !empty($openId['data']) ? $openId['data'] : '',
                'setmeal_id'=> $setmeal_id,

            ];
            $params = serialize($params);
            $re         = call_web_cash_pay($htype_cn, $type, $openId['data'], 'wxpay', $amount, 0, 0, $params);
            if($re['status']==1) $this->ajaxReturn(1, $re['msg']);
            $url=$re['data']['data'];
            $str=$this->indexBase64($url);
            $re['data']['img_base']=$str;
            $this->ajaxReturn(0, 'ok', $re['data']);
        }
    }


    public function add_save_taotao($uid, $id, $type)
    {
        $info = M('set_taocan')->where(['id' => $id])->find();
        if (empty($info)) {
            $this->ajaxReturn(1, '套餐已过期');
        }
    }


    /**
     * 收藏简历
     */
    public function resume_favor()
    {
        $rid = I('rid');
        $r = D('CompanyFavorites')->add_favorites($rid, C('visitor'));
        if ($r['state']) {
            $this->ajaxReturn(0, $r['error']);
        } else {
            $this->ajaxReturn(1, $r['error']);
        }
    }


    /**
     * 将简历保存为word
     */
    public function resume_doc()
    {
        $id = I('rid', 0);
        if (!$id) $this->ajaxReturn(1, '请选择简历！');

        $email = I('email', '');
        $body = I('body', '');
        $note = I('note', '');
        $is_show=I('is_show',0);
        if (empty($email)) {
            $this->ajaxReturn(1, '请填写邮箱');
        }
        if (!fieldRegex($email, 'email')) {
            $this->ajaxReturn(1, '邮箱格式错误，请重新输入');
        }
        $res = D('Resume')->save_as_doc_word($id, '', C('visitor'), 1,$is_show);
        $site_url = M('config')->where(['name' => 'site_domain'])->find();
        $url = $site_url['value'] . $res['path'] . $res['name'];
        //  var_dump($res);
        $result = sendMail($email, $body, $note, $res['path'] . $res['name'], $res['name']);
       // var_dump($res);die;
        if ($result) {
            $ress = M('user_dao_chu_log')->add([
                'uid' => C('visitor.uid'),
                'email' => $email,
                'body' => $body,
                'note' => $note,
                'url' => $url,
                'name' => $res['wordname'],
                'rid' => $id,
                'add_time' => date('Y-m-d h:i:s', NOW_TIME),
            ]);

            if ($ress) $this->ajaxReturn(0, '成功', '');
        }
        $this->ajaxReturn(1, '失败，请重试', '');
    }


    /*
    已下载的简历
*/
    public function resume_down()
    {
        $where['company_uid'] = C('visitor.uid');
        $settr = I('get.settr', 0, 'intval');
        $page = I('page', 1);
        //$where['is_del']=0;
        $page_size = I('page_size', 10);
        $settr && $where['down_addtime'] = array('gt', strtotime("-" . $settr . " day")); //筛选 下载时间
        $state = I('get.state', ''); // 简历标记状态
        $down_list = D('CompanyDownResume')->get_down_resume_api($where, $state, $page, $page_size);
        $list['list'] = $down_list['list'];
        $list['total'] = $down_list['count'];
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * 删除收藏的简历
     */

    public function resume_down_del()
    {
        $id = I('id', 0);
        $type = I('type', 1); //1 下载 2 顾问推荐 3 收藏 4 投递简历
        if (!in_array($type, [1, 2, 3])) {
            $this->ajaxReturn(1, '类型错误');
        }
        !$id && $this->ajaxReturn(1, '下载简历不存在');
        switch ($type) {
            case 1:
                $info = D('CompanyDownResume')->where(['did' => $id])->find();
                $res = D('CompanyDownResume')->where(['did' => $id])->setField('is_del', 1);
                break;
            case 2:
                $info = [];//D('CompanyDownResume')->where(['did'=>$id])->find();
                $res = 0;//D('CompanyDownResume')->where(['did'=>$id])->setField('is_del',1);
                break;
            case 3:
                $info = D('CompanyFavorites')->where(['did' => $id])->find();
                $res = D('CompanyFavorites')->where(['did' => $id])->setField('is_del', 1);
                break;
            case 4:
                $info = D('CompanyFavorites')->where(['did' => $id])->find();
                $res = D('CompanyFavorites')->where(['did' => $id])->setField('is_del', 1);
                break;
        }

        if ($res) {
            $row = M('company_resume_del')->where(['company_uid' => $info['company_uid'], 'resume_id' => $info['resume_id']])->find();
            if (empty($row)) {
                M('company_resume_del')->add([
                    'company_uid' => $info['company_uid'],
                    'resume_id' => $info['resume_id'],
                    'addtime' => NOW_TIME,
                ]);
            }
        }
        $this->ajaxReturn(0, '成功', '');
    }


    /*
		收藏的简历
	*/
    public function resume_favorites()
    {

        $where['company_uid'] = C('visitor.uid');
        $settr = I('get.settr', 0, 'intval');
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $settr && $where['favorites_addtime'] = array('gt', strtotime("-" . $settr . " day")); //筛选 收藏时间
        $favorites = D('CompanyFavorites')->get_favorites_api($where, $page, $page_size);
        $list['list'] = $favorites['list'];
        $list['total'] = $favorites['count'];
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * 获取删除过的简历
     */
    public function get_del_resume()
    {
        $where['company_uid'] = C('visitor.uid');
        $settr = I('get.settr', 0, 'intval');
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $settr && $where['favorites_addtime'] = array('gt', strtotime("-" . $settr . " day")); //筛选 收藏时间
        $favorites = D('CompanyFavorites')->get_company_del_api($where, $page, $page_size);
        $list['list'] = $favorites['list'];
        $list['total'] = $favorites['count'];
        $this->ajaxReturn(0, '', $list);
    }


    /**
     * 收到的投递简历
     */
    public function jobs_apply()
    {
        $where['company_uid'] = C('visitor.uid');
        $personal_look = I('personal_look', -1);
        if ($personal_look != -1) {
            $where['personal_look'] = $personal_look;   //1 未查看  2 已看
        }
        if(I('jobs_id')){
            $where['pj.jobs_id']=I('jobs_id');
        }
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $stop = I('get.stop', 0, 'intval');
        $settr = I('get.settr', 0, 'intval');
        $settr && $where['apply_addtime'] = array('gt', strtotime("-{$settr} day")); //筛选简历
        $jobs_id = I('get.jobs_id', 0, 'intval');
        $jobs_id && $where['jobs_id'] = $jobs_id; //筛选简历
        $is_reply = I('get.is_reply', 0, 'intval');
        $where['is_reply'] = $is_reply == 0 ? 0 : array('gt', 0);
        // 筛选项 -> 标签 (0->全部  1->合适  2->不合适  3->待定  4->未接通)
        $state = I('get.state', 0, 'intval');
        // 筛选项 -> 来源 (0->全部  1->委托投递  2->主动投递 )
        $is_apply = I('get.is_apply', 0, 'intval');
        $is_apply && $where['is_apply'] = $is_apply;
        $personal_apply_mod = D('PersonalJobsApply');
        $condition['uid'] = C('visitor.uid');
        (!$stop && C('qscms_jobs_display') == 1) && $condition['audit'] = 1;
        $jobs_list = M('Jobs')->where($condition)->getField('id,jobs_name');
        if ($stop) {
            $jobs_list_tmp = M('JobsTmp')->where(array('uid' => C('visitor.uid')))->getField('id,jobs_name');
            if ($jobs_list_tmp) {
                $jobs_list = $jobs_list ? ($jobs_list + $jobs_list_tmp) : $jobs_list_tmp;
            }
        }
        $jobsid_arr = array();
        foreach ($jobs_list as $key => $value) {
            $jobsid_arr[] = $key;
        }
        if (!empty($jobsid_arr) && !$where['jobs_id']) {
            $where['pj.jobs_id'] = array('in', $jobsid_arr);
        }
        $list = [];
        if ($jobsid_arr) {
            $apply_list = $personal_apply_mod->get_apply_jobs_api($where, 1, $state, $page_size, $page);
            $list['list'] = $apply_list['list'];
            $list['total'] = $apply_list['total'] ? $apply_list['total'] : 0;
        } else {
            $list['list'] = [];
            $list['total'] = 0;
        }
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * 获取简历数量
     */

    public function get_jobs_apply_count()

    {
        $data = JobsInfoModel::get_res_count();
        $this->ajaxReturn(0, '', $data);
    }

    /**
     * 工程币购买记录
     */

    public function gcb_order_info()

    {
        $where['order_type'] = 15;
        $where['is_paid']=2;
        $where['uid']=C('visitor.uid');
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $_list = D('Order')->get_order_list_api($where, $page, $page_size);
        $list['list'] = $_list['list'];
        $list['total'] = $_list['page_params']['totalRows'];
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * 工程币的使用记录
     */

    public function gcb_use_log()
    {
        $where['uid'] = C('visitor.uid');
        $where['use_type'] = 'gcb';
        $where['order_type']=['not in',['buy_gcb']];
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $list = JobsInfoModel::get_member_use_log($where, $page, $page_size);
        $this->ajaxReturn(0, '', $list);
    }

    /**
     * @param  $order_type string resume_down 简历下载  fa_bu 职位发布  buy 购买  guwen_service 顾问服务
     * 获取现金支付的记录
     */
    public function get_wxpay_log()
    {
        $order_type = I('order_type', '');
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $where = [];
        if (empty($order_type)) {
            $where['order_type'] = $order_type;
        }
        $list = JobsInfoModel::get_wxpay_log($where, $page, $page_size);
        $this->ajaxReturn(0, '', $list);
    }


    protected function _cominfo_flge()
    {
        //当前用户的企业信息
        $this->company_profile = M('CompanyProfile')->where(array('uid' => C('visitor.uid')))->find();

        if ($this->company_profile) {
            // 判断是否需要完善信息
            $this->cominfo_flge = true;
            $array = array("companyname", "nature", "scale", "district", "trade", "contents", "contact", "address");
            foreach ($this->company_profile as $key => $value) {
                if (in_array($key, $array) && empty($value)) {
                    $this->cominfo_flge = false;
                    break;
                }
            }
        } else {
            $this->cominfo_flge = false;
        }
    }

    /**
     * 验证修改的发布城市id 是否和之前一样
     * @param array $old_jobs_infos
     * @param array $new_jobs_info
     */
    public function check_fa_bu_ids($old_jobs_infos=[],$new_jobs_info=[])
    {
//        $a1=array(23,43,67,34,64);//新
//        $a2=array(43,23,1,2,67);//老
       $result=array_diff($new_jobs_info,$old_jobs_infos);
       $count=count($result);
       //验证职位名称
       $data['city_count']=$count;
       $data['is_edit']=1;
       $data['is_shou']=0;
       if($old_jobs_infos['jobs_name']!=$new_jobs_info['jobs_name']){
           $data['is_edit']=1;
           $data['is_shou']=1;
       }
       if($data['nature']!=$data['nature']){
           $data['is_edit']=1;
           $data['is_shou']=1;
       }
       if($count>0){
           $data['is_edit']=1;
           $data['is_shou']=1;
       }
       return $data;
    }

    /**
     * 发布修改职位
     */
    public function jobs_addOredit()
    {
        $this->_cominfo_flge();
        if (!$this->cominfo_flge) {
            $this->ajaxReturn(1, '为了达到更好的招聘效果，请先完善您的企业资料！');
        }
        //对座机进行分隔
        $telarray = explode('-', $this->company_profile['landline_tel']);

        $setmeal = D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));

        // 统计有效职位数
//        $jobs_num = D('Jobs')->where(array('uid' => C('visitor.uid')))->count();
//        $jobs_num_tmp = D('JobsTmp')->where(array('uid' => C('visitor.uid'), 'display' => 1))->count();
//        if ($setmeal[''] + $jobs_num_tmp >= $setmeal['jobs_meanwhile'] && I('request.id', 0, 'intval') == 0) {
//                $this->ajaxReturn(1, '当前显示的职位已经达到最大限制，请升级服务套餐!');
//        }
        $zhao_type = I('zhao_type', 0);
        if (!in_array($zhao_type, [1, 2, 3, 4, 5])) {
            $this->ajaxReturn(1, '类型错误');
        }
        // 保存 POST 数据
        // 插入职位信息
        $data = JobsInfoModel::check_fabu_params();
        if ($data['status']) {
            $this->ajaxReturn(1, $data['msg']);
        }
        $jobs_info = '';
        $setsqlarr = $data['data'];
      //  var_dump($data);die;
        if ($id = I('post.id', 0, 'intval')) {
            $setsqlarr['id'] = $id;
            $jobs_info = D('Jobs')->find($id);
            if (!$jobs_info) {
                $jobs_info = D('JobsTmp')->find($id);
            }
            $name = 'edit_jobs';
//            $new_jobs_info=array(23,43,67,34,64);//新
//            $old_jobs_infos=array(43,23,1,2,67);//老
//            $result=array_diff($setsqlarr['fa_bu_ids'],$jobs_info['fa_bu_ids']);
//            $count=count($result);
            $result=array_diff(explode(',',$setsqlarr['fa_bu_ids']),explode(',',$jobs_info['fa_bu_ids']));
            $count=count($result);
           if($jobs_info['jobs_name']!=$setsqlarr['jobs_name'] || $jobs_info['nature']!=$setsqlarr['nature'] || $count){
               $setsqlarr['is_shou']=1;
           }else{
               $setsqlarr['is_shou']=0;
           }
            $setsqlarr['is_edit']=1;
            S('jobs_info',$jobs_info);
        } else {
            $setsqlarr['addtime'] = time();
            $name = 'add_jobs';
            //分站信息调取
            if (C('subsite_info') && C('subsite_info.s_id') != 0) {
                $setsqlarr['subsite_id'] = C('subsite_info.s_id');
            }
            //end
        }
    //    var_dump($setsqlarr);die;
        $setsqlarr['setmeal_deadline'] = $setmeal['endtime'];
        $setsqlarr['deadline'] = $setsqlarr['setmeal_deadline'];
        $setsqlarr['setmeal_id'] = $setmeal['setmeal_id'];
        $setsqlarr['setmeal_name'] = $setmeal['setmeal_name'];
        $setsqlarr['uid'] = C('visitor.uid');
        $setsqlarr['company_id'] = $this->company_profile['id'];
        $setsqlarr['company_addtime'] = $this->company_profile['addtime'];
        $setsqlarr['companyname'] = $this->company_profile['companyname'];
        $setsqlarr['company_audit'] = $this->company_profile['audit'];
        C('apply.Sincerity') && $setsqlarr['famous'] = $this->company_profile['famous'];
        if (!$id) {
            $setsqlarr['audit'] = 2;
        } else {
            if ($this->company_profile['audit'] == 1) {
                if (C('qscms_audit_verifycom_editjob') == '-1') {
                    if ($jobs_info['audit'] == 3) {
                        $setsqlarr['audit'] = 2;
                    } else {
                        $setsqlarr['audit'] = $jobs_info['audit'];
                    }
                } else {
                    $setsqlarr['audit'] = C('qscms_audit_verifycom_editjob');
                }
            } else {
                if (C('qscms_audit_unexaminedcom_editjob') == '-1') {
                    if ($jobs_info['audit'] == 3) {
                        $setsqlarr['audit'] = 2;
                    } else {
                        $setsqlarr['audit'] = $jobs_info['audit'];
                    }
                } else {
                    $setsqlarr['audit'] = C('qscms_audit_unexaminedcom_editjob');
                }
            }
        }

     //   var_dump($setsqlarr);die;
        $rst = D('Jobs')->$name($setsqlarr, C('visitor'));
        if ($rst['state'] == 0) {
            $this->ajaxReturn(0, $rst['error']);
        }
        if ($jobs_info) {
            if ($setsqlarr['audit'] != $jobs_info['audit']) {
                switch ($setsqlarr['audit']) {
                    case 1:
                        $audit_str = '审核通过';
                        break;
                    case 2:
                        $audit_str = '审核中';
                        break;
                    case 3:
                        $audit_str = '审核未通过';
                        break;
                    default:
                        $audit_str = '';
                        break;
                }
                if ($audit_str) {
                    $auditsqlarr['jobs_id'] = $jobs_info['id'];
                    $auditsqlarr['reason'] = '自动设置';
                    $auditsqlarr['status'] = $audit_str;
                    $auditsqlarr['addtime'] = time();
                    $auditsqlarr['audit_man'] = '系统';
                    M('AuditReason')->data($auditsqlarr)->add();
                }
            }
        } else {
            switch ($setsqlarr['audit']) {
                case 1:
                    $audit_str = '审核通过';
                    break;
                case 2:
                    $audit_str = '';
                    break;
                case 3:
                    $audit_str = '审核未通过';
                    break;
                default:
                    $audit_str = '';
                    break;
            }
            if ($audit_str) {
                $auditsqlarr['jobs_id'] = $rst['id'];
                $auditsqlarr['reason'] = '自动设置';
                $auditsqlarr['status'] = $audit_str;
                $auditsqlarr['addtime'] = time();
                $auditsqlarr['audit_man'] = '系统';
                M('AuditReason')->data($auditsqlarr)->add();
            }
        }
        if (C('qscms_jobs_display') == 2) {
            baidu_submiturl(url_rewrite('QS_jobsshow', array('id' => $rst['id'])), 'addjob');
        }
        $this->ajaxReturn(0, $id ? '修改成功！' : '添加成功！', array('url' => U('company/jobs_list'), 'insertid' => $rst['id']));
    }

    /**
     * 修改发布的简历
     */
    public function jobs_edit_info()
    {
        $jid = I('jid', 0);
        !$jid && $this->ajaxReturn(1, '职位不存在');
        $info = M('jobs')->field('*,jobs_name as job_name,zhao_type_id as zhao_type,category as job_cate_id,trade as trade_id,district as city_id,experience as experience_id,education as education_id
        ,nature as nature_id,tag as jobtag_id,js_email as email,contents as gw_zhi_ze
        ')->where(['id' => $jid])->find();
        $cate_top_info = explode(',', $info['topclass']);
        $cate_info = explode(',', $info['category']);
        $row = '';
        foreach ($cate_top_info as $k => $v) {
            $row .= $v . '-' . $cate_info[$k] . ',';
        }
        if($info['fa_bu_ids']){
            $ids_arr=explode(',',$info['fa_bu_ids']);
            $info['fa_bu_info']=M('category_district')->where(['id'=>['in',$ids_arr]])->field('id,categoryname')->select();
        }
        if ($row) {
            $row = substr($row, 0, strlen($row) - 1);
        }
        $cate_ids=explode(',',$info['job_cate_id']);
        $top_ids=explode(',',$info['topclass']);
        $trade_ids=explode(',',$info['trade_id']);
        $top_trade_ids=explode(',',$info['top_trade']);
        foreach ($top_ids as $k=>$v){
            $cates_id.=$v.'-'.$cate_ids[$k].',';
        }
        foreach ($top_trade_ids as $k=>$v){
            $trades_id.=$v.'-'.$trade_ids[$k].',';
        }
        $trade_ids=substr($trades_id,0,strlen($trades_id)-1);
        $cate_ids=substr($cates_id,0,strlen($cates_id)-1);
        $info['job_cate_id']=$cate_ids;
        $info['trade_id']=$trade_ids;
        $wage_info = D('Category')->category_wage();
        if($info['wage_id']){
            $info['wage_cn'] = $wage_info[$info['wage_id']] . 'k';
        }else{
            $info['wage_cn'] =$info['duan_qi_money'];
        }

        $dao_gang_info = D('Category')->category_dao_gang_api();
       // var_dump($dao_gang_info);die;
        $info['dao_gang_cn'] = $dao_gang_info[$info['dao_gang_id']];
        $work_time_info = D('Category')->category_work_time_api();
        $info['work_time_cn'] = $work_time_info[$info['work_time_id']];
        $city_info=explode('.',$info['city_id']);
        $info['city_id']=$city_info[2];
        $this->ajaxReturn(0, '', $info);
    }

    /**
     * 获取发布职位的分类数据
     */

    public function get_all_cate()
    {
        $language_level = D('Category')->category_get_by_alias('QS_language_level', 'language_level'); //语言等级
        $experience_list = $this->get_experience_list(); //工作经验
        $education_list = $this->get_education_list();//学历
        $nature_list = $this->get_nature_list();//工作性质
        $trade_list = D('CategoryMajor')->get_engineering_and_children();//工程类别
        $qs_wage = D('Category')->category_wage_copy();//薪资
        $city_list = D('CategoryDistrict')->get_city_and_children_no_qg(0);//城市
        $jobs_cate = D('CategoryJobs')->get_all_cate();//职位分类
        $jobtag = D('Category')->category_get_by_alias('QS_jobtag', 'jobtag');//福利标签
        $zhao_type = $this->get_type_list_copy();//发布的招聘类型
        $work_time = D('Category')->category_get_by_alias('QS_work_time', 'work_time'); //工作时间
        $dao_gang_type = D('Category')->category_get_by_alias('QS_dutytime ', 'dutytime_dao'); //到岗时间
        $language = D('Category')->category_get_by_alias('QS_language', 'language'); //语言
        $current_list   =   D('Category')->category_current();  //求职状态
        $data['zhao_type'] = $zhao_type;
        $data['language_level'] = $language_level;
        $data['experience_list'] = $experience_list;
        $data['education_list'] = $education_list;
        $data['nature_list'] = $nature_list;
        $data['trade_list'] = $trade_list;
        $data['qs_wage'] = $qs_wage;
        $data['city_list'] = $city_list;
        $data['jobs_cate'] = $jobs_cate;
        $data['jobtag'] = $jobtag;
        $data['work_time'] = $work_time;
        $data['dao_gang'] = $dao_gang_type;
        $data['language'] = $language;
        $data['current_list']=$current_list;
        $this->ajaxReturn(0, '', $data);
    }

    /**
     * 计算发布支付的价格
     * @param $jobs_info
     * @param $job_id
     * @param $type 发布类型
     * @param $day  项目工期
     * @return mixed
     */

    protected function get_price($jobs_info, $job_id, $type, $day)
    {
        $zhao_type_info = M('category_pin')->where(['id' => $jobs_info['zhao_type_id']])->find();
        $gu_wen_ser_money = M('config')->where(['name' => 'gw_service_money'])->find();
        $taocan = D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));
        $money_info = seal_month_price($jobs_info,$type);
        if($type==1){
            $gu_wen_ser_money['value'] = $money_info['service_money'];
        }else{
            if($jobs_info['fa_type']==4){
                $gu_wen_ser_money['value'] = $money_info['service_money'];
            }else{
                $gu_wen_ser_money['value'] = $money_info['service_money']*$jobs_info['amount'];
            }
        }
        //修改 查找修改了几次城市
        if($jobs_info['is_edit']){
            $old_jobs_infos=S('jobs_info');
            $new_jobs_info=$jobs_info;
            //判断是否修改了职位名称
            //判断是否修改i工程类别
            if($jobs_info['is_shou']){
                $check_info=$this->check_fa_bu_ids($old_jobs_infos,$new_jobs_info);
                $count=$check_info['city_count'];
                $zhao_type_info['price']=$zhao_type_info['price']*$count;
                $info=$this->check_price($type,$day,$zhao_type_info,$job_id,$gu_wen_ser_money);
                $price=$info['price'];
                $gu_wen_ser_money=$info['gu_wen_ser_money'];
            }else{
                $price=$gu_wen_ser_money['value']+0;
            }
        }else{
            $fa_ids=explode(',',$jobs_info['fa_bu_ids']);
            $zhao_type_info['price']=$zhao_type_info['price']*count($fa_ids);
            $info=$this->check_price($type,$day,$zhao_type_info,$job_id,$gu_wen_ser_money);
            $price=$info['price'];
            $gu_wen_ser_money=$info['gu_wen_ser_money'];
         }
        $data['price'] = $price;
        $data['service_money'] = $gu_wen_ser_money['value'];
        return $data;
    }

    /**
     * 求出价格
     * @param $type
     * @param $day
     * @param $zhao_type_info
     * @param $job_id
     * @param $gu_wen_ser_money
     * @return array
     */
    public function check_price($type,$day,$zhao_type_info,$job_id,$gu_wen_ser_money)
    {
        if ($type == 1) {
            $taocan=D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));

            if (empty($taocan)) {

                $price = $zhao_type_info['price'];
            } else {
                $jobs_info = M('jobs')->where(['id' => $job_id])->find();
                $price = $gu_wen_ser_money['value'] + $zhao_type_info['price'];

                if ($jobs_info['zhao_type_id'] == 1) { //常规
                    if ($taocan['cg_fa_count'] - $taocan['cg_yi_fa_count'] > 0) {
                        $price = 0;
                    }
                } elseif ($jobs_info['zhao_type_id'] == 2) { //急招
                    if ($taocan['ji_zhao_fa_count'] - $taocan['ji_zhao_yi_fa_count'] > 0) {
                        $price = 0;
                    }
                } elseif ($jobs_info['zhao_type_id'] == 3) { //短期
                    if ($taocan['duan_qi_fa_count'] - $taocan['duan_qi_yi_fa_count'] > 0) {
                        $price = 0;
                    }
                } elseif ($jobs_info['zhao_type_id'] == 4) { //项目专场
                    if ($taocan['xmzc_fa_count'] - $taocan['xmzc_yi_fa_count'] > 0) {
                        $price = 0;
                    }
                } elseif ($jobs_info['zhao_type_id'] == 5) { //悬赏
                    $price = 0;
                }
            }
        } else {
            if ($day < 90 && $day != 0) {
                $gu_wen_ser_money['value'] = 0;
            }
            $taocan = D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));
            if (empty($taocan)) {
                $price = $gu_wen_ser_money['value'] + $zhao_type_info['price'];
            } else {
                $jobs_info = M('jobs')->where(['id' => $job_id])->find();
                $price = $gu_wen_ser_money['value'] + $zhao_type_info['price'];
                if ($jobs_info['zhao_type_id'] == 1) { //常规
                    if ($taocan['cg_fa_count'] - $taocan['cg_yi_fa_count'] > 0) {
                        $price = $gu_wen_ser_money['value'];
                    }
                } elseif ($jobs_info['zhao_type_id'] == 2) { //急招
                    if ($taocan['ji_zhao_fa_count'] - $taocan['ji_zhao_yi_fa_count'] > 0) {
                        $price = $gu_wen_ser_money['value'];
                    }
                } elseif ($jobs_info['zhao_type_id'] == 3) { //短期
                    if ($taocan['duan_qi_fa_count'] - $taocan['duan_qi_yi_fa_count'] > 0) {
                        $price = $gu_wen_ser_money['value'];
                    }
                } elseif ($jobs_info['zhao_type_id'] == 4) { //项目专场
                    if ($taocan['xmzc_fa_count'] - $taocan['xmzc_yi_fa_count'] > 0) {
                        $price = $gu_wen_ser_money['value'];
                    }
                } elseif ($jobs_info['zhao_type_id'] == 5) { //悬赏
                    $price = $gu_wen_ser_money['value'] + $zhao_type_info['price'];
                }
            }
        }

        return ['gu_wen_ser_money'=>$gu_wen_ser_money,'price'=>$price];
    }


    /**
     * 获取价格
     */

    public function edit_type_get_price()
    {
        $job_id = I('jobs_id', 0);
        !$job_id && $this->ajaxReturn(1, '职位不存在');
        $type = I('fa_type', 0);
        if (!in_array($type, [1, 2, 3])) {
            $this->ajaxReturn(1, '类型错误');
        }
        //1 常规 2 顾问找人才 3 悬赏找人才
        //判断是否存在套餐
        //存在扣除套餐
        //不存在 调起支付
        //返回提示
        //todo 设置顾问服务把自己  和  发布职位的价格
        $jobs_info = M('jobs')->where(['id' => $job_id])->find();
        $jobs_info['fa_type']=$type;
        $arr = $this->get_price($jobs_info, $job_id, $type, $jobs_info['xm_day']);
        $price = $arr['price'];
        $sev_moner = $arr['service_money'];
        //修改职位的发布类型     //判断是否存在订单或是否支付
        $yi_kou_price = I('yi_kou_price', 0);
        if ($price==0 && $type == 1) {
            //生成已经支付的订单
            //生成一个订单
         $order=   D('Order'  )->where(array('jobs_id' => $job_id))->find();
         if($order){
//             if($order['fa_type']!=1 && $order['fa_type']!=4){
//                 $this->ajaxReturn(1,'订单类型错误1');
//             }
             D('Order')->where(array('id' => $order['id']))->setField('is_paid',1);
             $res = D('Order')->order_paid($order['oid'], NOW_TIME);
             JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'use_taocan','修改发布职位',date('Y-m-d H:i:s',$order['payment_time']),'fa_bu');


             $order_insert_id=$order['id'];
         }else{
             $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号
             $description = '发布职位：' . $jobs_info['jobs_name'];
             $order_insert_id = D('Order')->add_order(C('visitor'), $oid, 16, $price, $price, 0, $jobs_info['jobs_name'], 'use_taocan', '套餐次数支付', '发布职位', time(), 1, 0, 0, time(), '', '', '', 0, 0, $job_id);
             /* 会员日志 */
             write_members_log(C('visitor'), 'order', '创建发布职位订单（订单号：' . $oid . '），支付方式：套餐次数支付', false, array('order_id' => $order_insert_id));
             $time = time();
             $order = D('Order')->where(array('id' => $order_insert_id))->find();
             D('Order')->where(array('id' => $order_insert_id))->save([
                 'fa_type'=>$type,
             ]);
             $res = D('Order')->order_paid($order['oid'], $time);
             JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'use_taocan','发布职位',date('Y-m-d H:i:s',$order['payment_time']),'fa_bu');
             M('jobs')->where(['id' => $job_id])->setField('fa_type', $type);
             M('jobs_search')->where(['id' => $job_id])->setField('fa_type', $type);

         }
            $data['price'] = $price;
            $data['fa_type'] = $type;
            $data['jobs_id'] = $job_id;
            $data['uid'] = C('visitor.uid');
            $data['order_insert_id'] = $order_insert_id;
            $this->ajaxReturn(0, '', $data);
        } else {
            if($type!=1) {
                if($jobs_info['fa_type']==4){
                    $this->ajaxReturn(1,'顾问已经推荐人才了，不能在通过其他途径了哟');
                }
                if($jobs_info['audit']==1){
                    $this->ajaxReturn(1,'发布中的职位在通过其他途径了哟');
                }
                if ($jobs_info['xm_day'] < 90 && $jobs_info['xm_day'] != 0) {
                    //获取一口价
                    if (!$yi_kou_price) {
                        $this->ajaxReturn(1, '请填写一口价');
                    }
                    $res= $this->check_yi_kou_price($jobs_info,$yi_kou_price);
                    if($res['status']){
                        $this->ajaxReturn(1,$res['msg']);
                    }
                    $price += $yi_kou_price;
                }
                $data['xi_shu'] = 0;
                if ($type == 3 && ($jobs_info['xm_day'] >= 90 || $jobs_info['xm_day']==0)) {
                    $xi_shu = I('xi_shu', 0);
                    if (empty($xi_shu)) {
                        $this->ajaxReturn(1, '请选择保证金系数');
                    }

                    $price = $price * $xi_shu;
                    $data['xi_shu'] = $xi_shu;
                    M('jobs')->where(['id' => $job_id])->setField('xishu_rate', $xi_shu);
                }
            }
            $data['price'] = $price;
            $data['fa_type'] = $type;
            $data['jobs_id'] = $job_id;
            $data['uid'] = C('visitor.uid');
            $data['yi_kou_price'] = $yi_kou_price ? $yi_kou_price : 0;
            $data['order_insert_id'] = 0;
            $this->ajaxReturn(0, '', $data);
        }
    }

    /**
     * 验证一口价
     * @param $jobs_info
     * @param $yi_kou_price
     * @return array
     */
    public function check_yi_kou_price($jobs_info,$yi_kou_price)
    {
            //获取一口价
            $money_info = M('config')->where(['name' => ['in', ['one_month', 'two_month', 'three_month']]])->select();
            $data = [];
            foreach ($money_info as $k => $v) {
                $data[$v['name']] = $v['value'];
            }
            $xm_day = $jobs_info['xm_day'];
            if ($xm_day < 90 && $xm_day>=60 && $yi_kou_price < $data['three_month']) {
                return ['status'=>1,'msg'=>'金额不能低于' . $data['three_month']];
            }
             if ($xm_day < 60 &&  $xm_day>=30 && $yi_kou_price < $data['two_month']) {
                return ['status'=>1,'msg'=>'金额不能低于' . $data['two_month']];
             }
          if ($xm_day < 30 && $yi_kou_price < $data['one_month']) {
                return ['status'=>1,'msg'=>'金额不能低于' . $data['one_month']];
            }

            return ['status'=>0,'msg'=>''];
    }

     /**
     * 添加发布订单
     */
    public function add_fabu_order()
    {
        $job_id = I('jobs_id', 0);
        !$job_id && $this->ajaxReturn(1, '职位不存在');
        $type = I('fa_type', 0);
        $userinfo   = I('post.userinfo');//微信登陆用户信息
        if (!in_array($type, [1, 2, 3])) {
            $this->ajaxReturn(1, '类型错误');
        }
        //查看开始是否存在 发布的订单
        $jobs_o_info=M('order')->where(['jobs_id'=>$job_id])->find();
        $jobs_info=M('jobs')->where(['id'=>$job_id])->find();
      //  var_dump($jobs_o_info['is_paid']==1 && !in_array($jobs_o_info['fa_type'],[2,3]));die;
//        if($jobs_o_info['is_paid']==1 && !in_array($jobs_o_info['fa_type'],[2,3])){
//            $this->ajaxReturn(1, '请等待审核');
//        }
        if($jobs_info['audit']==1 && in_array($jobs_info['fa_type'],[1,4]) && in_array($type,[2,3])){
            $this->ajaxReturn(1,'发布中的职位在通过其他途径了哟');
        }
        if($jobs_o_info && !$jobs_o_info['service_money']){
            M('order')->where(['id'=>$jobs_o_info['id']])->setField('is_paid',1);
        }
        $payment_name = I('payment_name', '');//wxpay   gcb
        if (empty($payment_name)) {
            $this->ajaxReturn(1, '请选择支付方式');
        }
        if($payment_name=='wxpay'){
            $payment_cn='微信支付';
        }elseif ($payment_name=='gcb'){
            $payment_cn='工程币支付';
        }elseif ($payment_name=='remittance'){
            $payment_cn='线下转账';
        }
        $jobs_info = M('jobs')->where(['id' => $job_id])->find();
        $yi_kou_price = I('yi_kou_price', 0);

        $arr = $this->get_price($jobs_info, $job_id, $type, $jobs_info['xm_day']);
        $price = $arr['price'];

        $service = $arr['service_money'];
        if($type!=1){
            if ($jobs_info['xm_day'] < 90 && $jobs_info['xm_day']!=0) {
                if (empty($yi_kou_price)) {
                    $this->ajaxReturn(1, '请填写一口价');
                }
                M('jobs')->where(['id' => $job_id])->setField('yi_kou_price', $yi_kou_price);
                $price += $yi_kou_price;
                $service+=$yi_kou_price;
            }
        }
        if ($jobs_info['xishu_rate'] > 0) {
            $price = $price * $jobs_info['xishu_rate'];
            $service =$service*$jobs_info['xishu_rate'];
        }
      //  var_dump($price);die;
        if ($price >= 6000 && $payment_name != 'remittance') {
            $this->ajaxReturn(1, "高于6000请线下付款！");
        }
        //生成顾问的类型订单
        if (in_array($type, [1,2, 3])) {//工程币支付
            if ($payment_name == 'gcb') {
//                $mobile = I('mobile', 0);
//
//                if (!S('mgcb_' . $mobile)) {
//                    $this->ajaxReturn(1, '验证码不存在或已过期');
//                }
//                if (S('mgcb_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
//                    $this->ajaxReturn(1, '验证码不存在或已过期');
//                }
//                S('mgcb_' . $mobile, null);


                $gcb_info = D('MembersSetgcb')->get_user_setmeal(C('visitor.uid'));
                if (empty($gcb_info)) {
                    $this->ajaxReturn(1, '您目前没有工程币套餐');
                }
                if ($gcb_info['all_num'] - $gcb_info['use_num'] < $price) {
                    $this->ajaxReturn(1, '您的工程币余额不足');
                }
                //生成一个订单
                $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号

                $description = '发布职位：' . $jobs_info['jobs_name'];
        if(empty($jobs_o_info)){
            $order_insert_id = D('Order')->add_order(C('visitor'), $oid, 16, $price, $price, 0, $jobs_info['jobs_name'], $payment_name, $payment_cn, '发布职位', time(), 1, 0, 0, time(), '', '', '', 0, 0, $job_id, $type);
            /* 会员日志 */
            //修改累计支付金额
//            D('Order')->where(array('id' => $order_insert_id))->save([
//                'all_total'=>['exp','all_total+'.$price],
//            ]);
            write_members_log(C('visitor'), 'order', '创建发布职位订单（订单号：' . $oid . '），支付方式：工程币支付', false, array('order_id' => $order_insert_id));
            //添加 todo 一个支付看记录
        }else{
            $order_insert_id=$jobs_o_info['id'];
            //修改累计支付金额
            D('Order')->where(array('id' => $order_insert_id))->save([
            //   'all_total'=>['exp','all_total+'.$price],
                'fa_type'=>$type,
                'pay_amount'=>$price,
                'amount'=>$price,
                'payment'=>$payment_name,
                'payment_cn'=>$payment_cn,
                'is_paid'=>1,
            ]);
            //添加 todo 一个修改支付看记录
        }
                $time = time();
                $order = D('Order')->where(array('id' => $order_insert_id))->find();
//                $res = D('Order')->order_paid($order['oid'], $time);
//                if ($res) {
//                    D('MembersSetgcb')->where(['uid' => $order['uid']])->setInc('use_num', $price);
//                    M('jobs')->where(['id' => $job_id])->setField('fa_type', $type);
                    $this->edit_zhao_type_id($type, $job_id, $order_insert_id, $service);
//                    //修改发布类型   减少发布次数
                   $this->ajaxReturn(0, '发布成功', $order_insert_id);
//                }
            } elseif ($payment_name == 'remittance') {
                //线下转账
                //生成一个订单
                $oid = "P-" . date('ymd', time()) . "-" . date('His', time()); //订单号

                $description = '发布职位：' . $jobs_info['jobs_name'];
                if(empty($jobs_o_info)){
                    $order_insert_id = D('Order')->add_order(C('visitor'), $oid, 16, $price, $price, 0, $jobs_info['jobs_name'], $payment_name, $payment_cn, '发布职位', time(), 1, 0, 0, time(), '', '', '', 0, 0, $job_id, $type);
                    /* 会员日志 */
                    //修改累计支付金额
//                    D('Order')->where(array('id' => $order_insert_id))->save([
//                        'all_total'=>['exp','all_total+'.$price]
//                    ]);

                    write_members_log(C('visitor'), 'order', '创建发布职位订单（订单号：' . $oid . '），支付方式：线下转账支付', false, array('order_id' => $order_insert_id));
                }else{
                    $order_insert_id=$jobs_o_info['id'];
                    //修改累计支付金额
                    D('Order')->where(array('id' => $order_insert_id))->save([
                       // 'all_total'=>['exp','all_total+'.$price],
                        'pay_amount'=>$price,
                        'amount'=>$price,
                        'fa_type'=>$type,
                        'payment'=>$payment_name,
                        'payment_cn'=>$payment_cn,
                        'is_paid'=>1,
                    ]);
                }
                if ($order_insert_id) {
                    M('jobs')->where(['id' => $job_id])->setField('fa_type', $type);
                    M('jobs_search')->where(['id' => $job_id])->setField('fa_type', $type);
                    $this->edit_zhao_type_id($type, $job_id, $order_insert_id, $service);
                    $this->ajaxReturn(0, '成功，请等待管理员审核', $order_insert_id);
                } else {
                    $this->ajaxReturn(1, '下单出错');
                }
            } elseif ($payment_name == 'use_taocan') {

            } else {
                //微信
                $htype_cn       = $htype_cn_mianfei =D('Order')->order_type[16];
//                $wxcode         = I('post.wxcode','','trim,badword');
//                if (empty($wxcode)) $this->ajaxReturn(1, '微信wxcode不能为空');
//                $openId     = wxOpenId($wxcode, $this->userinfo['uid']);
//                if (!empty($openId['status'])) $this->ajaxReturn(1, '微信openId获取失败');
                $params  = [
                    'jobs_id'   => $job_id,//职位ID
                    'amount'    => $price,
                    'openid'    => !empty($openId['data']) ? $openId['data'] : '',
                    'fa_type'   => $type
                ];
                $params = serialize($params);
                //=====现金支付=====
              //  $re = call_cash_pay($htype_cn, 16, $openId['data'], 'wxpay', $price, 0, 0, $params);
               // $price=0.01;
                $re = call_web_cash_pay($htype_cn, 16, $openId['data'], 'wxpay', $price, 0, 0, $params);



                if($re['status']==1) $this->ajaxReturn(1, $re['msg']);
                if($re['data']['insert_id']){
                    M('jobs')->where(['id' => $job_id])->setField('fa_type', $type);
                    M('jobs_search')->where(['id' => $job_id])->setField('fa_type', $type);
                }
                $url=$re['data']['data'];
                $str=$this->indexBase64($url);
                $re['data']['img_base']=$str;
                $this->edit_zhao_type_id($type, $job_id, $re['data']['insert_id'], $service);
                $this->ajaxReturn(0, 'ok', $re['data']);
            }
        } else {
            //常规发布 职位  支付

        }

    }

    /**
     * 发布悬赏 修改类型
     * @param $type
     * @param $jobs_id
     * @param $order_id
     * @param $service_money
     * @return bool
     */
    public function edit_zhao_type_id($type, $jobs_id, $order_id, $service_money)
    {
        if ($type == 3) {
            $setsqlarr=M('jobs')->where(['id'=>$jobs_id])->find();
            $setsqlarr['zhao_type_id']=5;
            $setsqlarr['zhao_type_name']='悬赏职位';
            $setsqlarr['id']=$jobs_id;
            $setsqlarr['topclass']=explode(',',$setsqlarr['topclass']);
            $setsqlarr['category']=explode(',',$setsqlarr['category']);
            $city_info=explode('.',$setsqlarr['district']);
            $setsqlarr['district']=$city_info[2];
            $rst = D('Jobs')->edit_jobs($setsqlarr, C('visitor'));
        }elseif ($type==2){
            $setsqlarr=M('jobs')->where(['id'=>$jobs_id])->find();
            $setsqlarr['zhao_type_id']=6;
            $setsqlarr['zhao_type_name']='通过顾问职位';
            $setsqlarr['id']=$jobs_id;
            $setsqlarr['topclass']=explode(',',$setsqlarr['topclass']);
            $setsqlarr['category']=explode(',',$setsqlarr['category']);
            $city_info=explode('.',$setsqlarr['district']);
            $setsqlarr['district']=$city_info[2];
            $rst = D('Jobs')->edit_jobs($setsqlarr, C('visitor'));
        }
        M('order')->where(['id' => $order_id])->setField('service_money', $service_money);
        return true;
    }

    /**
     * 检查订单是否支付
     */

    public function check_pay()
    {
        $oid = I('order_id', 0);
        file_put_contents('order_id.txt',$oid);
        !$oid && $this->ajaxReturn(1, '订单不存在');
        $order_info = D('Order')->where(['id' => $oid])->find();
        if (empty($order_info)) {
            $this->ajaxReturn(1, '订单信息不存在');
        }
        if ($order_info['is_paid'] != 2) {
            $this->ajaxReturn(1, '订单未支付');
        }
        $res = D('Resume')->save_as_doc_word($order_info['rid'], '', C('visitor'), 1,1);
        $site_url = M('config')->where(['name' => 'site_domain'])->find();
        $url = $site_url['value'] . $res['path'] . $res['name'];
        //  var_dump($res);
        $order_info['url']=$url;
        $this->ajaxReturn(0, '', $order_info);
    }

    /**
     * 获取所有人才顾问
     * $user_type  人才数量 0 不限 1 0-100  2 100-1000 3 1000以上
     * $trade_id   擅长工程类别
     * $jobs_cate_id 擅长 职位类别
     * $level   顾问等级
     */
    public function get_all_guwen()
    {
        $where=$this->get_where();
        $page=I('page',1);
        $page_size=I('page_size',10);
       // var_dump($where);die;
        $list = M('members')->join('as m right join qs_resume as q on m.uid=q.uid')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,q.fullname as username,m.advisor_level as level,q.good_trade,q.good_jobs')
            ->where($where)
            ->page($page,$page_size)->order('user_count desc,uid desc')->select();
   // var_dump(M('members')->getLastSql());die;
       $count= M('members')->join('as m right join qs_resume as q on m.uid=q.uid')
           ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,q.fullname as username,,m.advisor_level as level,q.good_trade,q.good_jobs')
           ->where($where)->count();

        $trade_list=   D('CategoryMajor')->get_major_list();
        foreach ($list as $k => $v) {
            $jian_info = M('resume')->field('good_jobs,good_trade')->where(['uid' => $v['uid']])->find();
            //顾问的擅长的职位
//            $list[$k]['intention_jobs'] = $jian_info['intention_jobs'];
//            $list[$k]['major_cn'] = $jian_info['major_cn'];
//            $list[$k]['major_cn']=$trade_list[$jian_info['good_trade']]['categoryname'];
//            $arr=explode(',',$jian_info['good_jobs']);
//            $ids=[];
//            foreach ($arr as $k1=>$v1){
//                $cate_jobs=explode('.',$v1);
//                if(isset($cate_jobs[1])){
//                    $ids[]=$cate_jobs[1];
//                }else{
//                    $ids[]=$cate_jobs[0];
//                }
//
//            }
//            $tra_arr=explode(',',$jian_info['good_trade']);
//       //     $ids=[];
//            $tra_names=[];
//            foreach ($tra_arr as $k1=>$v1){
//                $cate_jobs=explode('.',$v1);
//                if(isset($cate_jobs[1])){
//                    $tra_names[]=  $trade_list[$cate_jobs[1]]['categoryname'] ;//$cate_jobs[1];
//                }else{
//                    $tra_names[]=$trade_list[$cate_jobs[0]]['categoryname'];//$cate_jobs[0];
//                }
//            }
//            $list[$k]['major_cn']=implode(',',$tra_names);
////            if($v['uid']==29){
////                $names=M('category_jobs')->where(['id'=>['in',$ids]])->getField('categoryname',true);
////                var_dump(M('category_jobs')->getLastSql());
////                var_dump($ids);die;
////            }
//           //die;
//            $names=M('category_jobs')->where(['id'=>['in',$ids]])->getField('categoryname',true);
//            $list[$k]['intention_jobs']=implode(',',$names);
            $data=get_guwen_good_trade_job( $v['uid'],$trade_list);
            $list[$k]['intention_jobs']=$data['intention_jobs'];
            $list[$k]['major_cn']=$data['major_cn'];
            $list[$k]['count'] = M('guwen_user')->where(['status' => 0, 'guwen_id' => $v['uid']])->count();
            $list[$k]['level_log'] = M('guwen_level')->where(['id' => $v['level']])->getField('logo');
            $list[$k]['sex'] = M('resume')->where(['uid' => $v['uid']])->getField('sex');
            $list[$k]['avatars']=avatar($v['uid']);
            //todo 查询是否收藏 'com_uid'=>C('visitor.uid'),
            //                 'gw_uid'=>$gw_id,
            $info = M('gw_collection_comp')->where(['com_uid' => C('visitor.uid'), 'gw_uid' => $v['uid']])->find();
            $list[$k]['is_colle'] = $info ? 1 : 0;
        }

        $data['total']=$count;
        $data['list']=$list;
        $this->ajaxReturn(0, '', $data);
    }

    /**
     * 获取顾问的搜索数据
     */

    public function get_guwen_search_all()
    {
        $level = $this->level_api(); //顾问等级
        $user_type = [
            [
                'categoryname' => '0-100',
                'id' => 1,
            ],
            [
                'categoryname' => '100-1000',
                'id' => 2,
            ],
            [
                'categoryname' => '1000以上',
                'id' => 3,
            ],
        ];//人才数量
        //擅长职位
        $jobs = [];
        //求出所有的职位id
        $job_cate_ids=M('jobscate_search')->where(['type'=>2])->getField('type_id',true);
        $jobs_cate=M('category_jobs')->field('id,categoryname,parentid')->where(['id'=>['in',$job_cate_ids]])->select();
        //擅长工程
        $trade = [];
        //
        $trade_ids=M('jobscate_search')->where(['type'=>1])->getField('type_id',true);
        $trade=M('category_major')->field('id,categoryname,parentid')->where(['id'=>['in',$trade_ids]])->select();
        $data=[
            [
              'name'=>'擅长工程类别',
              'data'=>$trade,
              'value'=>'trade_id',
            ],
            [
                "name"=>'擅长职位类别',
                'data'=>$jobs_cate,
                'value'=>'jobs_cate_id'
            ],
            [
                "name"=>'顾问等级',
                'data'=>$level,
                'value'=>'level'
            ],
            [
                "name"=>'简历库人数',
                'data'=>$user_type,
                'value'=>'user_type'
            ],
        ];
//        $data['trade'] = $trade;
//        $data['jobs_cate'] = $jobs_cate;
//        $data['level'] = $level;
//        $data['user_type'] = $user_type;
        $this->ajaxReturn(0, '', $data);
    }

    /**
     * 选择保存顾问
     */

     public function check_guwen()
    {
        $ids = I('ids', 0);
        $jobs_id = I('jobs_id', 0);
        $order_id = I('order_id', 0);
        $job_info = M('jobs')->where(['id' => $jobs_id])->find();
        if (empty($job_info)) {
            $this->ajaxReturn(1, '职位不存在');
        }
        $order_info = M('order')->where(['id' => $order_id,'is_paid'=>2])->find();
        if (empty($order_info)) {
            $this->ajaxReturn(1, '订单不存在');
        }
        //判断订单是否停止
        $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
        if($jobs_order['is_stop']){
            $this->ajaxReturn(1,'订单已停止');
        }

//        $res=check_is_can_tui($jobs_id,$order_info['uid'],$order_id);
//        if(!$res){
//            $this->ajaxReturn(1,'录用人数已满');
//        }

        $ids_arr = explode(',', $ids);
        if (count($ids_arr) > 3) {
            $this->ajaxReturn(1, '顾问最多选择三人');
        }
        $count= M('gu_wen_jie_dan_order')->where([
            'jobs_id' => $jobs_id,
            'comp_uid' => C('visitor.uid'),
            'fa_bu_order'=>$order_id,
            'order_status'=>['in',[0,1,2,3,5,6,7]]
        ])->count();
        if(($count+count($ids_arr)) > 3){
            $this->ajaxReturn(1, '顾问最多选择三人');
        }
        $ids_arr = array_unique($ids_arr);
        $rows=M('jobs_add_gu_wen')->where(['gw_uid'=>['in',$ids_arr],'jobs_id'=>$jobs_id,'status'=>1])->getField('gw_uid',true);
        if($rows){
           $names=M('resume')->where(['uid'=>['in',$rows]])->getField('fullname',true);
           $name_str=implode(',',$names);
           $this->ajaxReturn(1,$name_str.'已经选择了,请重新选择');
        }
        //添加职位的顾问信息
        foreach ($ids_arr as $k => $v) {
            if (empty($v)) {
                continue;
            }
            $row= M('jobs_add_gu_wen')->where([
                'jobs_id' => $jobs_id,
                'gw_uid' => $v,
                'com_uid' => C('visitor.uid'),
            ])->find();
            if(empty($row)){
                M('jobs_add_gu_wen')->add([
                    'jobs_id' => $jobs_id,
                    'gw_uid' => $v,
                    'com_uid' => C('visitor.uid'),
                    'add_time' => date('Y-m-d H:i:s', NOW_TIME),
                    'status' => 1,//1 正常  2 已取消
                ]);
                //添加订单
                M('gu_wen_jie_dan_order')->add([
                    'jobs_id' => $jobs_id,
                    'fa_bu_order' => $order_id,
                    'gw_uid' => $v,
                    'order_status' => 0,//0 未接单 1. 已接单 2 已取消
                    'is_comment' => 0,//  是否评论 0 未 1 已
                    'add_time' => NOW_TIME,
                    'comp_uid' => C('visitor.uid'),//企业id
                    'zhao_type' => $job_info['zhao_type_id'],
                    'fa_type' => $job_info['fa_type'],
                ]);
            }else{
                if($row['status']==2){
                    M('jobs_add_gu_wen')->where([
                        'jobs_id' => $jobs_id,
                        'gw_uid' => $v,
                        'com_uid' => C('visitor.uid'),
                    ])->setField('status',1) ;
                    M('gu_wen_jie_dan_order')->where([
                        'jobs_id' => $jobs_id,
                        'fa_bu_order' => $order_id,
                        'gw_uid' => $v,
                        'comp_uid' => C('visitor.uid'),//企业id
                        'fa_type' => $job_info['fa_type'],
                    ])->setField('order_status',0);
                }
            }
        }
        $this->ajaxReturn(0, '成功');
    }

    /**
     * 收藏或者取消收藏
     */
    public function collection_guwen()
    {
        $gw_id = I('uid', 0);
        $type = I('type', 1);//1 收藏 2取消
        !$gw_id && $this->ajaxReturn(1, '顾问不存在');
        if ($type == 1) {
            $re = M('gw_collection_comp')->add([
                'com_uid' => C('visitor.uid'),
                'gw_uid' => $gw_id,
                'add_time' => date('Y-m-d H:i:s', NOW_TIME),
            ]);
        } else {
            $re = M('gw_collection_comp')->where(['com_uid' => C('visitor.uid'), 'gw_uid' => $gw_id])->delete();
        }
        !$re && $this->ajaxReturn(1, '失败了， 请重试');
        $this->ajaxReturn(0, '操作成功');
    }

    public function get_where()
    {
        $user_type = I('user_type', 0);
        $trade_id = I('trade_id', 0);
        $jobs_cate_id = I('jobs_cate_id', 0);
        $level = I('level', 0);
        $key=I('key','');
        if($key){
            $where['fullname']=['like',"%$key%"];
        }
        if($jobs_cate_id){
            $cate_ids="+good_jobs".$jobs_cate_id;
            $where["q.key_full"] = ['match_mode', [$cate_ids]];
//            $where_job=M('category_jobs')->where(['id'=>$jobs_cate_id])->find();
//            if($where_job['parentid']==0){
//                $jobs_cate_id=$jobs_cate_id;
//            }else{
//                $jobs_cate_id=$where_job['parentid'].'.'.$jobs_cate_id;
//            }
//
//            $where['q.good_jobs']=['like',"%$jobs_cate_id%"];
        }
        if($trade_id){
            $trade_ids="+good_trade".$trade_id;
            $where["q.key_full"] = ['match_mode', [$trade_ids]];
           // $where['q.good_trade']=$trade_id;
        }
      //var_dump($where);die;
        if($level){
            $where['m.advisor_level']=$level;
        }
        $where['m.utype']=3;
        //1 0-100   2 100-1000   3 >1000
        if($user_type){
            switch ($user_type){
                case 1:
                    $where['m.user_count']=['between',"0,100"];
                    break;
                case 2:
                    $where['m.user_count']=['between',"100,1000"];
                    break;
                case 3:
                    $where['m.user_count']=['gt',1000];
                    break;
            }
        }

        return $where;
    }
    /**
     * 收藏顾问列表
     */
    public function get_collection_list()
    {

        $where=$this->get_where();
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $list = M('gw_collection_comp')->join('as gc left join qs_members as m on gc.gw_uid=m.uid')
            ->join('right join qs_resume as q on m.uid=q.uid')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,m.username,m.advisor_level as level')
            ->where(['gc.com_uid' => C('visitor.uid')])->page($page, $page_size)->select();
        $count= M('gw_collection_comp')->join('as gc left join qs_members as m on gc.gw_uid=m.uid')
            ->join('right join qs_resume as q on m.uid=q.uid')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,m.username,m.advisor_level as level')
            ->where(['gc.com_uid' => C('visitor.uid')])
            ->where($where)
            ->count();
        $trade_list=   D('CategoryMajor')->get_major_list();

        foreach ($list as $k => $v) {
            $jian_info = M('resume')->field('fullname,good_jobs,good_trade')->where(['uid' => $v['uid']])->find();
            //顾问的擅长的职位

            $data=get_guwen_good_trade_job( $v['uid'],$trade_list);
            $list[$k]['intention_jobs']=$data['intention_jobs'];
            $list[$k]['major_cn']=$data['major_cn'];

            $list[$k]['count'] = M('guwen_user')->where(['status' => 0, 'guwen_id' => $v['guwen_id']])->count();
            $list[$k]['level_log'] = M('guwen_level')->where(['id' => $v['level']])->getField('logo');
            $list[$k]['sex'] = M('resume')->where(['uid' => $v['uid']])->getField('sex');
            $list[$k]['avatars']=avatar($v['uid']);
            $list[$k]['username']=$jian_info['fullname'];
        }
        $data['list']=$list;
        $data['total']=$count;
        $this->ajaxReturn(0, '', $data);
    }
    /**
     * 我的合作顾问列表
     */
    public function get_he_zuo_list()
    {
        $where=$this->get_where();
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $list = M('gu_wen_jie_dan_order')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname, m.username,m.advisor_level as level')
            ->join('as j left join qs_members as m on j.gw_uid=m.uid')
            ->join('right join qs_resume as q on m.uid=q.uid')
            ->where($where)
            ->where(['comp_uid' => C('visitor.uid'),'j.order_status'=>['not in',[0]]])
            ->page($page, $page_size)->order('j.id desc')
            ->group('m.uid')->select();
        $count = M('gu_wen_jie_dan_order')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,m.username,m.advisor_level as level')
            ->join('as j left join qs_members as m on j.gw_uid=m.uid')
            ->join('right join qs_resume as q on m.uid=q.uid')
            ->where($where)
            ->where(['comp_uid' => C('visitor.uid'),'j.order_status'=>['not in',[0]]])
            ->group('m.uid')->count();
        $trade_list=   D('CategoryMajor')->get_major_list();
        foreach ($list as $k => $v) {
            $jian_info = M('resume')->field('fullname,good_jobs,good_trade')->where(['uid' => $v['uid']])->find();
            //顾问的擅长的职位
//            $list[$k]['intention_jobs'] = $jian_info['intention_jobs'];
//            $list[$k]['major_cn'] = $jian_info['major_cn'];
//            $list[$k]['major_cn']=$trade_list[$jian_info['good_trade']]['categoryname'];
//            $cate_jobs=explode('.',$jian_info['good_jobs']);
//            $list[$k]['intention_jobs']=M('category_jobs')->where(['id'=>$cate_jobs[1]])->getField('categoryname');
            $data=get_guwen_good_trade_job( $v['uid'],$trade_list);
            $list[$k]['intention_jobs']=$data['intention_jobs'];
            $list[$k]['major_cn']=$data['major_cn'];
            $list[$k]['count'] = M('guwen_user')->where(['status' => 0, 'guwen_id' => $v['guwen_id']])->count();
            $list[$k]['level_log'] = M('guwen_level')->where(['id' => $v['level']])->getField('logo');
            $list[$k]['sex'] = M('resume')->where(['uid' => $v['uid']])->getField('sex');
            $info = M('gw_collection_comp')->where(['com_uid' => C('visitor.uid'), 'gw_uid' => $v['uid']])->find();
            $list[$k]['is_colle'] = $info ? 1 : 0;
            $list[$k]['avatars']=avatar($v['uid']);
            $list[$k]['username']=$jian_info['fullname'];
        }
        $data['list']=$list;
        $data['total']=$count;
        $this->ajaxReturn(0, '', $data);
    }

    /**
     * 获取保证金风险提示
     */
    public function get_baozhengjin_notice()
    {
        $info = M('help')->where(['id' => 1])->find();
        $info['content'] = htmlspecialchars_decode($info['content'], ENT_QUOTES);
        //$info['content']=htmlspecialchars($info['content']);
        echo <<<HTML
            <!doctype html>
            <html lang="zh">
            <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
            <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <title>{$info['title']}</title>
            </head>
            <body>
              <h3>{$info['title']}</h3>
              <div>
              {$info['content']}
            </div>
            </body>
            </html>
HTML;
    }

    /**
     * 工程币购买须知
     */
    public function get_gcbbuy_notice()
    {
        $info = M('help')->where(['id' => 2])->find();
        $info['content'] = htmlspecialchars_decode($info['content'], ENT_QUOTES);
        //$info['content']=htmlspecialchars($info['content']);
        echo <<<HTML
            <!doctype html>
            <html lang="zh">
            <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
            <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <title>{$info['title']}</title>
            </head>
            <body>
              <h3>{$info['title']}</h3>
              <div>
              {$info['content']}
            </div>
            </body>
            </html>
HTML;
    }

    /**
     * 工程桥增值服务协议
     */
    public function get_zzfw_notice()
    {
        $info = M('help')->where(['id' => 3])->find();
        $info['content'] = htmlspecialchars_decode($info['content'], ENT_QUOTES);
        //$info['content']=htmlspecialchars($info['content']);
        echo <<<HTML
            <!doctype html>
            <html lang="zh">
            <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
            <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <title>{$info['title']}</title>
            </head>
            <body>
              <h3>{$info['title']}</h3>
              <div>
              {$info['content']}
            </div>
            </body>
            </html>
HTML;
    }

    /**
     * 工程桥增值服务协议
     */
    public function get_remittance_notice()
    {
        $info = M('help')->where(['id' => 4])->find();
        $info['content'] = htmlspecialchars_decode($info['content'], ENT_QUOTES);
        //$info['content']=htmlspecialchars($info['content']);
        echo <<<HTML
            <!doctype html>
            <html lang="zh">
            <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
            <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <title>{$info['title']}</title>
            </head>
            <body>
              <h3>{$info['title']}</h3>
              <div>
              {$info['content']}
            </div>
            </body>
            </html>
HTML;
    }



    /**
     * 获取顾问主动推荐保证金系数
     */
    public function get_xi_shu()
    {
        $info = M('config')->where(['name' => 'gu_wen_bao_xi'])->getField('value');
        $info = explode(',', $info);
        $this->ajaxReturn(0, '', $info);
    }

    /**
     * 获取悬赏找人保证金系数
     */
    public function get_xuan_shang_xi_shu()
    {
        $info = M('config')->where(['name' => 'xuan_shang_gu_wen_bao_xi'])->getField('value');
        $info = explode(',', $info);
        $this->ajaxReturn(0, '', $info);
    }


    /**
     * 顾问接单详情
     */
    public function jie_order_detail()
    {
        $order_id = I('order_id', 0);
        !$order_id && $this->ajaxReturn(1, '订单信息不存在');
        $order_info = M('gu_wen_jie_dan_order')->where(['id' => $order_id])->find();
        //查询顾问推荐的人才
        //var_dump($order_info);die;
        $fa_order_info=M('order')->where(['id'=>$order_info['fa_bu_order']])->find();
     //   var_dump($fa_order_info);die;
        $jobs_info=M('jobs')->field('duan_qi_money,trade_cn,category_cn,jobs_name,experience_cn,education_cn,wage_id,company_id')->where(['id'=>$order_info['jobs_id']])->find();
        $info=M('jobs')->where(['id'=>$order_info['jobs_id']])->find();
        $ru_zhi_info = seal_month_price($info);
        if($fa_order_info['fa_type']==4){
         $xishu_info=M('guwen_tui_jian_rusume')->field('xishu_rate,resume_uid,desc,comp_uid,tui_status')->where(['guwen_uid'=>c('visitor.uid'),'order_id'=>$order_info['id'],'jobs_id'=>$order_info['jobs_id']])->order('xishu_rate desc')->find();
         if($xishu_info['xishu_rate']>0){
             $jobs_info['ru_zhi'] = $ru_zhi_info['ru_zhi']*$xishu_info['xishu_rate'];
             $jobs_info['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month']*$xishu_info['xishu_rate'];
         }else{
             $jobs_info['ru_zhi'] = $ru_zhi_info['ru_zhi'];
             $jobs_info['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
         }
        }else{
            $jobs_info['ru_zhi'] = $ru_zhi_info['ru_zhi'];
            $jobs_info['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
        }
        $wage_info = D('Category')->category_wage();
        if($jobs_info['wage_id']){
            $jobs_info['wage_cn'] = $wage_info[$jobs_info['wage_id']] . 'k';
        }else{
            $jobs_info['wage_cn'] = $jobs_info['duan_qi_money'];
        }

        $jobs_info['oid']=$fa_order_info['oid'];
        $jobs_info['order_status']=$order_info['order_status'];
        $com_info=M('company_profile')->where(['id'=>$jobs_info['company_id']])->getField('logo');
        $jobs_info['qy_logo']= $com_info? attach($com_info, 'company_logo'): C('qscms_site_domain') . __ROOT__ . '/data/upload/company_logo/default.png';
        //查询推荐的人才
        //推荐的用户
        //0 未处理 1 录用 2未录用 3 未满月离职 4 入职满月
        $tui_users=M('guwen_tui_jian_rusume')->field('resume_uid,desc,comp_uid,tui_status')->where(['guwen_uid'=>c('visitor.uid'),'order_id'=>$order_info['id'],'jobs_id'=>$order_info['jobs_id']])->select();
        foreach($tui_users as $k=>$v){
            $user_info=M('members')->where(['uid'=>$v['resume_uid']])->find();
            $jian_info=M('resume')->field('fullname,intention_jobs,major_cn,trade_cn,current_cn,education_cn,experience_cn,refreshtime')->where(['uid'=>$v['resume_uid']])->find();
            //       var_dump($jian_info);die;
            $tui_users[$k]['intention_jobs']=$jian_info['intention_jobs'];
            $tui_users[$k]['major_cn']=$jian_info['trade_cn'];
            $tui_users[$k]['sex']=M('resume') ->where(['uid'=>$v['guwen_id']])->getField('sex');
            $tui_users[$k]['avatars']=avatar($v['resume_uid']);
            //   $tui_users[$k]['avatar']=$user_info['avatars']?$this->get_site_url.'/'.$user_info['avatars']:'';
            $tui_users[$k]['education_cn']=$jian_info['education_cn']?$jian_info['education_cn']:'不限';
            $tui_users[$k]['experience_cn']=$jian_info['experience_cn']?$jian_info['experience_cn']:'不限';
            $tui_users[$k]['reg_time']=daterange(NOW_TIME,$jian_info['refreshtime']);
         //   $tui_users[$k]['username']=$user_info['username'];
             $tui_users[$k]['is_down']=$this->check_down_resume($v['resume_uid'],$v['comp_uid']);
             $tui_users[$k]['username']=$jian_info['fullname']?$jian_info['fullname']:$user_info['username'];
            //   $tui_users[$k]['']
        }
        $data['jobs_info']=$jobs_info;
        $data['tui_users']=$tui_users;
        $this->ajaxReturn(0,'',$data);

    }

    /**
     * 顾问接单
     */
    public function jie_order()
    {
        $jobs_id = I('jobs_id', 0);
        $order_id = I('order_id');
        $jobs_info = M('jobs')->where(['jobs_id' => $jobs_id])->find();
        !$jobs_info && $this->ajaxReturn(1, '职位不存在');
        $order_info = M('gu_wen_jie_dan_order')->where(['fa_bu_order' => $order_id,'gw_uid'=>C('visitor.uid')])->find();
        !$order_info && $this->ajaxReturn(1, '订单不存在');
        if ($order_info['order_status'] == 4) {
            $this->ajaxReturn(1, '订单已超时');
        }
        if($order_info['order_status']==1){
           $this->ajaxReturn(1,'订单已接单');
        }
        //判断订单是否停止
        $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
        if($jobs_order['is_stop']){
            $this->ajaxReturn(1,'订单已停止');
        }
//        $res=check_is_can_tui($jobs_id,$order_info['comp_uid'],$order_id);
//        if(!$res){
//            $this->ajaxReturn(1,'录用人数已满');
//        }
        $user_info = $this->userinfo;
        if ($user_info['utype'] != 3) {
            $this->ajaxReturn(1, '用户身份错误');
        }



        $re = M('gu_wen_jie_dan_order')->where(['fa_bu_order' => $order_id])->setField('order_status', 1);
        if ($re) {
            $data['time'] = time();
            $data['jobs_id'] = $jobs_id;
            $data['uid'] = C('visitor.uid');
            S('jie_dan_time'.$jobs_id, $data, ['expire' => 86400 * 3]);
            $this->ajaxReturn(0, '成功');
        }
        $this->ajaxReturn(1, '出错了，请重试');
    }
//

    /**
     * 推荐简历
     */
    public function gw_tui_resume()
    {
        $jobs_id = I('jobs_id', 0);
        $order_id = I('order_id', 0);
        $jobs_info = M('jobs')->where(['id' => $jobs_id])->find();
        !$jobs_info && $this->ajaxReturn(1, '职位不存在');
        $order_info = M('gu_wen_jie_dan_order')->where(['id' => $order_id])->find();
        !$order_info && $this->ajaxReturn(1, '订单不存在');
        //判断订单是否停止
        $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
        if($jobs_order['is_stop']){
            $this->ajaxReturn(1,'订单已停止');
        }
//        $res=check_is_can_tui($jobs_id,$order_info['comp_uid'],$order_info['fa_bu_order']);
//        if(!$res){
//            $this->ajaxReturn(1,'录用人数已满');
//        }
        //判断订单是否停止
        $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
        if($jobs_order['is_stop']){
            $this->ajaxReturn(1,'订单已停止');
        }
        if ($order_info['order_status'] == 2) {
            $this->ajaxReturn(1, '订单已取消');
        }
        // todo 判断企业是否申请退款
        $uids = I('uids', 0);
        if (empty($uids)) {
            $this->ajaxReturn(1, '请选择人才');
        }
        $uids_arr = explode(',', $uids);
        if(!in_array($jobs_info['zhao_type'],[5,6])){
            //判断是否有一口价
            //主动推荐
            if(count($uids_arr)>1){
                $this->ajaxReturn(1,'一次只能推荐一个哟');
            }
            $yi_kou_price=I('yi_kou_price',0);
            $xi_shu=I('xi_shu',0);
            if($jobs_info['xm_day'] >= 90 || $jobs_info['xm_day']==0){
                if(empty($xi_shu)){
                    $this->ajaxReturn(1,'请选择系数');
                }
                M('jobs')->where(['id'=>$jobs_id])->setField('xishu_rate',$xi_shu);
            }
            if ($jobs_info['xm_day'] < 90 && $jobs_info['xm_day'] != 0) {
                //获取一口价
                if (!$yi_kou_price) {
                    $this->ajaxReturn(1, '请填写一口价');
                }
                $res= $this->check_yi_kou_price($jobs_info,$yi_kou_price);
                if($res['status']){
                    $this->ajaxReturn(1,$res['msg']);
                }
                M('jobs')->where(['id'=>$jobs_info['id']])->setField('yi_kou_price',$yi_kou_price);
            }
            //     //计算保证金
            $arr = $this->get_price($jobs_info, $jobs_id, $order_info['fa_type'], $jobs_info['xm_day']);
            $price = $arr['price'];
            $sev_moner = $arr['service_money'];
            if($xi_shu){
                $sev_moner=$sev_moner*$xi_shu;
            }
          //  M('order')->where(['id'=>$order_info['id']])->setField('service_money',$sev_moner);
        }

        $desc = I('desc', '');
        $desc_id = I("desc_id", 0);
        if (empty($desc)) {
            $this->ajaxReturn(1, '请填写评语');
        }
       $lenth= iconv_strlen($desc,"UTF-8");
       if($lenth<20 || $lenth>300){
           $this->ajaxReturn('评语请在20字至300之间');
       }
        $result = JobsInfoModel::guwen_tui_jian($order_id, $jobs_id, $uids_arr, $desc, $jobs_info, 0,$sev_moner,$xi_shu);
        $this->ajaxReturn($result['status'], $result['msg']);
    }

    /**
     * 顾问的订单列表
     */

    public function guwen_orders()
    {
        $type = I('type', 0);//2 顾问找人才 3 悬赏找人才  4 推举人才
        if (!in_array($type, [2, 3, 4])) {
            $this->ajaxReturn(1, '类型错误');
        }
        $status = I('order_status', -1);
        $where = [];
        $where['go.gw_uid'] = C('visitor.uid');
        if ($type) {
            $where['go.fa_type'] = $type;
        }
        if ($status != -1) {
            $where['go.order_status'] = $status;
        }else{
            $where['go.order_status'] = ['in',[0,1,2,3,4,5,6,7]];
        }
    //file_put_contents('order_status.txt',$status);
        $page = I('page', 1);
        $page_size = I('page_size', 10);
        $orders = [];
      if (in_array($type, [2, 3,4])) {
            $orders = M('gu_wen_jie_dan_order')
                ->field('o.is_stop,o.payment_time,go.id,go.gw_is_comment,go.order_status,j.uid,go.jobs_id,j.duan_qi_money,j.zhao_type_id,j.trade_cn,j.company_id,j.wage_id,j.category_cn,j.experience_cn,jobs_name,j.education_cn,o.id as order_id,o.oid')
                ->join('as go left join qs_order as o on go.fa_bu_order=o.id')
                ->join('left join qs_jobs as j on go.jobs_id=j.id')
                ->where($where)->page($page, $page_size)->order('go.id desc')->select();
       }
        $jl_down_money = M('config')->where(['name' => 'jl_download_money'])->getField('value');
         //order_status 0 去接单 1 去投简历
        foreach ($orders as $k => $v) {
            $job_info = M('jobs')->where(['id' => $v['jobs_id']])->find();
            $ru_zhi_info = seal_month_price($job_info);
            if($job_info['fa_type']==4){
                $xishu_info=M('guwen_tui_jian_rusume')->field('xishu_rate,resume_uid,desc,comp_uid,tui_status')->where(['guwen_uid'=>c('visitor.uid'),'order_id'=>$v['id'],'jobs_id'=>$v['jobs_id']])->order('xishu_rate desc')->find();
                if($xishu_info['xishu_rate']>0){
                    $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi']*$xishu_info['xishu_rate'];
                    $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month']*$xishu_info['xishu_rate'];
                }else{
                    $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi'];
                    $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
                }
            }else{
                $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi'];
                $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
            }
//            $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi'];
//            $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
            $wage_info = D('Category')->category_wage();
            if($v['wage_id']){
                $orders[$k]['wage_cn'] = $wage_info[$v['wage_id']] . 'k';
            }else{
                $orders[$k]['wage_cn'] =$v['duan_qi_money'];
            }
            $orders[$k]['pay_time']=$v['payment_time']?date('Y-m-d',$v['payment_time']):'暂无';
            $orders[$k]['jl_down_price'] = $jl_down_money;
            $com_info=M('company_profile')->where(['id'=>$v['company_id']])->getField('logo');
            $orders[$k]['qy_logo']= $com_info? attach($com_info, 'company_logo'): C('qscms_site_domain') . __ROOT__ . '/data/upload/company_logo/default.png';
            //todo 查询订单的处理状态  简历未下载就是未下载状态  简历已下载就是 处理 中
            //没有 操作录用 就是未处理
            $orders[$k]['is_can_tui']=check_is_can_tui($v['jobs_id'],$v['uid'],$v['order_id']);
            //判断显示状态
        }
        $this->ajaxReturn(0, '', $orders);

    }


    /**
     * 悬赏职位顾问推荐简历
     */
    public function gw_xuanshang_tui_resume()
    {
        $jobs_id = I('jobs_id', 0);
        $jobs_info = M('jobs')->where(['id' => $jobs_id])->find();
        !$jobs_info && $this->ajaxReturn(1, '职位不存在');

        $uids = I('uids', 0);
        if (empty($uids)) {
            $this->ajaxReturn(1, '请选择人才');
        }
        $desc = I('desc', '');
        $desc_id = I("desc_id", 0);
        if (empty($desc)) {
            $this->ajaxReturn(1, '请填写评语');
        }
        if($jobs_info['fa_type']==3){
            //添加接单订单   //
            $order_info=M('order')->where(['jobs_id'=>$jobs_id])->order('id desc')->find();

            if(empty($order_info)){
                $this->ajaxReturn(1,'悬赏订单不存在');
            }
            //判断订单是否停止
            $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
            if($jobs_order['is_stop']){
                $this->ajaxReturn(1,'订单已停止');
            }
//            $res=check_is_can_tui($jobs_id,$order_info['uid'],$order_info['id']);
//            if(!$res){
//                $this->ajaxReturn(1,'录用人数已满');
//            }
            //判断是否收藏  收藏了修改状态为 意向订单状态
            $res=M('personal_favorites')->where(['personal_uid'=>C('visitor.uid'),'jobs_id'=>$jobs_id])->find();
            $row=M('gu_wen_jie_dan_order')->where(
                [
                    'jobs_id' => $jobs_id,
                    'fa_bu_order' => $order_info['id'],
                    'gw_uid' => C('visitor.uid'),
                    'order_status'=>['neq',4]
                ]
            )->find();
            if($row){
                $order_id=$row['id'];
                $uids_arr = explode(',', $uids);
                $result = JobsInfoModel::guwen_tui_jian($order_id, $jobs_id, $uids_arr, $desc, $jobs_info, 0);
                $this->ajaxReturn($result['status'], $result['msg'],[]);
              //  $this->ajaxReturn(1,'您已经结过单咯');
            }else{
                $status=1;
                if($res){
                    $status=5;
                }
                $order_id= M('gu_wen_jie_dan_order')->add([
                    'jobs_id' => $jobs_id,
                    'fa_bu_order' => $order_info['id'],
                    'gw_uid' => C('visitor.uid'),
                    'order_status' => $status,//0 未接单 1. 已接单  2 处理中 3已完成 4 已取消 5 意向
                    // 'is_comment' => 0,//  是否评论 0 未 1 已
                    'qy_is_comment'=>0,//是否评论 0 未 1 已
                    'add_time' => NOW_TIME,
                    'comp_uid' => $jobs_info['uid'],//企业id
                    'zhao_type' => $jobs_info['zhao_type_id'],
                    'fa_type' => 3,
                    'gw_is_comment'=>0,//是否评论 0 未 1 已
                ]);
                $uids_arr = explode(',', $uids);
                $result = JobsInfoModel::guwen_tui_jian($order_id, $jobs_id, $uids_arr, $desc, $jobs_info, 0);
                $this->ajaxReturn($result['status'], $result['msg'],[]);
            }
        }elseif($jobs_info['fa_type']==2){
            //顾问
            $ids = $uids;
            $job_info = M('jobs')->where(['id' => $jobs_id])->find();
            if (empty($job_info)) {
                $this->ajaxReturn(1, '职位不存在');
            }
            $order_info = M('order')->where(['jobs_id' => $jobs_id])->find();
            if (empty($order_info)) {
                $this->ajaxReturn(1, '订单不存在');
            }
            //判断订单是否停止
            $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
            if($jobs_order['is_stop']){
                $this->ajaxReturn(1,'订单已停止');
            }
//            $res=check_is_can_tui($jobs_id,$order_info['uid'],$order_info['id']);
//            if(!$res){
//                $this->ajaxReturn(1,'录用人数已满');
//            }

            $ids_arr = explode(',', $ids);
            if (count($ids_arr) > 3) {
                $this->ajaxReturn(1, '顾问最多选择三人');
            }
             //  $ids_arr = array_unique($ids_arr);
                $row= M('gu_wen_jie_dan_order')->where([
                    'jobs_id' => $jobs_id,
                    'fa_bu_order' => $order_info['id'],
                    'gw_uid' => C('visitor.uid'),
                ])->order('id desc')->find();
            if(empty($row)){
             $this->ajaxReturn(1,'订单不存在');
            }
            $uids_arr = explode(',', $uids);
            $result = JobsInfoModel::guwen_tui_jian($row['id'], $jobs_id, $uids_arr, $desc, $jobs_info, 0);
            $this->ajaxReturn($result['status'], $result['msg'],[]);
            $this->ajaxReturn(0, '成功');
        }
        else{
         //   file_put_contents('ttt.txt',json_encode($_POST));
            //其他接单
            $uid_arr=explode(',',$uids);
            if(count($uid_arr)>1){
                $this->ajaxReturn(1,'一次只能推荐一个哟');
            }
            $order_info=M('order')->where(['jobs_id'=>$jobs_id])->order('id desc')->find();
            //判断订单是否停止
            $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
            if($jobs_order['is_stop']){
                $this->ajaxReturn(1,'订单已停止');
            }
//            $res=check_is_can_tui($jobs_id,$order_info['uid'],$order_info['id']);
//            if(!$res){
//                $this->ajaxReturn(1,'录用人数已满');
//            }
            $row=M('gu_wen_jie_dan_order')->where(
                [
                    'jobs_id' => $jobs_id,
                    'fa_bu_order' => $order_info['id'],
                    'gw_uid' => C('visitor.uid'),
                    'order_status'=>['neq',4]
                ]
            )->find();

            if(!$row){
                $order_id= M('gu_wen_jie_dan_order')->add([
                    'jobs_id' => $jobs_id,
                    'fa_bu_order' => $order_info['id'],
                    'gw_uid' => C('visitor.uid'),
                    'order_status' => 7,//0 未接单 1. 已接单 6 待处理 2 处理中 3已完成 4 已取消 5 意向 7 未下载
                    // 'is_comment' => 0,//  是否评论 0 未 1 已
                    'qy_is_comment'=>0,//是否评论 0 未 1 已
                    'add_time' => NOW_TIME,
                    'comp_uid' =>$jobs_info['uid'],//企业id
                    'zhao_type' =>$jobs_info['zhao_type_id'],
                    'fa_type' => 4,
                    'gw_is_comment'=>0,//是否评论 0 未 1 已
                ]);
                M('jobs')->where(['id' => $jobs_id])->setField('fa_type', 4);
                M('jobs_search')->where(['id' => $jobs_id])->setField('fa_type', 4);
                M('order')->where(['id' => $order_info['id']])->setField('fa_type', 4);
            }else{
               $order_id=$row['id'];
            }
            $data['order_id']=$order_id;
            $data['uids']=$uids;
            $data['desc']=$desc;
            $data['desc_id']=$desc_id;
            $data['jobs_id']=$jobs_id;
            $data['zhao_type']=$jobs_info['zhao_type_id'];
           $this->ajaxReturn(0,'',$data);
        }
    }
    /**
     * 发布评价
     */
    public function fa_bu_comment()
    {
        $type=I('type',0);  //1 顾问 2 企业
        $order_id=I('order_id',0);
        $jobs_id=I('jobs_id',0);
       // $order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->find();
        $order_info=M('gu_wen_jie_dan_order')->where(['id'=>$order_id])->find();
        if($type==1){
            if(empty($order_info) || $order_info['gw_is_comment']){
                $this->ajaxReturn(1,'订单状态错误');
            }
            if($order_info['order_status']!=3){
                $this->ajaxReturn(1,'订单未完成');
            }
          $xin_zi=I('xin_zi',0);
          $lvyue=I('lvyue',0);
          $pei_he=I('pei_he',0);
            if(!$xin_zi || !$lvyue || !$pei_he){
                $this->ajaxReturn(1,'评分最低一星');
            }
           $re= $this->add_comment($type,$order_id,$jobs_id,$xin_zi,$lvyue,$pei_he);
          if($re){
           $this->ajaxReturn(0,'发布成功');
          }
          $this->ajaxReturn(1,'发布失败，请重试');
        }else{
            if(empty($order_info) || $order_info['qy_is_comment']){
                $this->ajaxReturn(1,'订单状态错误');
            }
          $xaing_ying=I('xiang_ying',0);
            $jl_zhi_liang    =I('jl_zhi_liang',0);
            $service_tai_du  =I('service_tai_du',0);
            $zhuanye       =I('zhuanye',0);
            $service_nl     =I('service_nl',0);
            if(!$zhuanye || !$jl_zhi_liang || !$service_tai_du || !$xaing_ying || !$service_nl){
                $this->ajaxReturn(1,'评分最低一星');
            }
            $re= $this->add_comment($type,$order_id,$jobs_id,0,0,0,$xaing_ying,$jl_zhi_liang,$service_tai_du,$zhuanye,$service_nl);
            if($re){
                $this->ajaxReturn(0,'发布成功');
            }
            $this->ajaxReturn(1,'发布失败，请重试');
        }

    }

    /**
     * 添加评论
     * @param $type  string 1 顾问 2 企业
     * @param $order_id string 订单id
     * @param $jobs_id  string 职位id
     * @param $xin_zi  string 薪资评分
     * @param $lvyue   string 履约评分
     * @param $pei_he  string 配合评分
     * @param int $xiang_ying 响应
     * @param int $jl_zhi_liang 简历质量
     * @param int $service_tai_du 服务太多
     * @param int $zhuangye  专业度
     * @param int $service_nl 服务能力
     * @return mixed
     */
    public function add_comment($type,$order_id,$jobs_id,$xin_zi,$lvyue,$pei_he,$xiang_ying=0,$jl_zhi_liang=0,$service_tai_du=0,$zhuanye=0,$service_nl=0)
    {

        $re=  M('comment')->add([
            'type'=>$type,
            'order_id'=>$order_id,
            'jobs_id'=>$jobs_id,
            'xin_zi'=>$xin_zi,
            'lvyue'=>$lvyue,
            'pei_he'=>$pei_he,
            'xiang_ying'=>$xiang_ying,
            'jl_zhi_liang'=>$jl_zhi_liang,
            'service_taidu'=>$service_tai_du,
            'zhuanye'=>$zhuanye,
            'service_nl'=>$service_nl,
            'add_time'=>time(),
        ]);
        if($re){
            //修改订单状态为已评价
            switch ($type){
                case 1:
                 //   M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->setField('gw_is_comment',1);
                    M('gu_wen_jie_dan_order')->where(['id'=>$order_id])->setField('gw_is_comment',1);
                    return true;
                    break;
                case 2:
                    M('gu_wen_jie_dan_order')->where(['id'=>$order_id])->setField('qy_is_comment',1);
                 //   M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->setField('qy_is_comment',1);
                    return true;
                    break;
                default:
                    return false;
                    break;
            }
        }
        return false;
    }

    /**
     * 企业订单
     * $type string 1 常规  2 通过顾问 3 过高悬赏 4 顾问推荐
     */
    public function qi_orders()
    {
      $type=I('type',0);
      if(empty($type)){
          $this->ajaxReturn(1,'类型错误');
      }
        $page=I('page',0);
        $page_size=I('page_size',10);
        $orders=M('order')
             ->field('o.is_stop,o.payment_time,o.oid,o.refund_status,j.company_id,o.is_paid,j.old_zhao_type_id as zhao_type_id,j.district_cn,j.zhao_end_time,j.addres_detail,j.id as jobs_id,j.jobs_name,j.trade_cn,j.category_cn,j.education_cn,j.experience_cn,j.wage_id,o.id,j.addtime')
             ->join('as o right join qs_jobs as j on o.jobs_id=j.id')
             ->where(['o.fa_type'=>$type,'o.uid'=>C('visitor.uid')])->page($page,$page_size)->order('o.id desc')->select();
     //  var_dump(M('order')->getLastSql());die;
        foreach($orders as $k=>$v){
            $job_info=M('jobs')->where(['id'=>$v['jobs_id']])->find();
            $ru_zhi_info = seal_month_price($job_info);

            if($job_info['fa_type']==4){
                $o_id=M('gu_wen_jie_dan_order')->where(['order_status'=>['in',[0,1,2,3,5,7,6]],'jobs_id'=>$v['jobs_id'],'fa_bu_order'=>$v['id'],'comp_uid'=>C('visitor.uid')])->order('id desc')->find();
                $xishu_info=M('guwen_tui_jian_rusume')->field('xishu_rate,resume_uid,desc,comp_uid,tui_status')->where(['guwen_uid'=>$o_id['gw_uid'],'order_id'=>$o_id['id'],'jobs_id'=>$v['jobs_id']])->order('xishu_rate desc')->find();
//var_dump($o_id);
//var_dump(M('guwen_tui_jian_rusume')->getLastSql());
         //    var_dump($orders);die;
                if($xishu_info['xishu_rate']>0){
                    $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi']*$xishu_info['xishu_rate'];
                    $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month']*$xishu_info['xishu_rate'];
                }else{
                    $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi'];
                    $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
                }
            }else{
                $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi'];
                $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
            }


//           $orders[$k]['ru_zhi'] = $ru_zhi_info['ru_zhi'];
//          $orders[$k]['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
            $wage_info = D('Category')->category_wage();
            if($job_info['wage_id']){
                $orders[$k]['wage_cn'] = $wage_info[$job_info['wage_id']] . 'k';
            }else{
                $orders[$k]['wage_cn'] = $job_info['duan_qi_money'];
            }
            $orders[$k]['pay_time']=$v['payment_time']?date('Y-m-d',$v['payment_time']):'暂无';
            $orders[$k]['addtime']=date('Y-m-d',$v['addtime']);
            $orders[$k]['tui_count']=M('guwen_tui_jian_rusume')->where(['jobs_id'=>$v['jobs_id']])->count();
            $com_info=M('company_profile')->where(['id'=>$v['company_id']])->getField('logo');
            $orders[$k]['qy_logo']= $com_info? attach($com_info, 'company_logo'): C('qscms_site_domain') . __ROOT__ . '/data/upload/company_logo/default.png';
            $check_count=  M('jobs_add_gu_wen')->where(['jobs_id'=>$v['jobs_id'],'status'=>1])->count();
            $orders[$k]['is_check']=$check_count?1:0;
            $orders[$k]['refund_status']=(int)$v['refund_status'];

            //查询企业简历下载记录
            $companyDown    = M('CompanyDownResume')->where(['company_uid'=>C('visitor.uid')])->getField('resume_uid', true);

            $gwTuiJian  = M('GuwenTuiJianRusume')->where(['resume_uid'=>['in', $companyDown],'jobs_id'=> $v['jobs_id'], 'comp_uid'=>C('visitor.uid'), ' tui_status'=>['in', [0,1]]])->find();
            if(!empty($gwTuiJian)) {
                $orders[$k]['is_chu']  =0;
            }else{
                $orders[$k]['is_chu']  =1;
            }
         }

      //  die;
        $data['list']=$orders;
        $data['total']= $orders=M('order')
            ->field('j.district_cn,j.zhao_end_time,j.addres_detail,j.id as jobs_id,j.jobs_name,j.trade_cn,j.category_cn,j.education_cn,j.experience_cn,j.wage_id,o.id,j.addtime')
            ->join('as o right join qs_jobs as j on o.jobs_id=j.id')
            ->where(['o.fa_type'=>$type,'o.uid'=>C('visitor.uid')])->count();
        $this->ajaxReturn(0,'',$data);
    }

    /**
     * 验证是否存在有没有处理的用户
     * @param $gw_uid
     * @param $order_id
     * @param $jobs_id
     * @return int
     */

    public function check_is_chuli($gw_uid,$order_id,$jobs_id)
    {
        $order_info=M('gu_wen_jie_dan_order')->where(['jobs_id'=>$jobs_id,'id'=>$order_id])
            ->find();
        if($order_info['order_status']==0 || $order_info['order_status']==5 || $order_info['order_status']==7){
            return  0;
        }else{
            $tui_user= $tui_users=M('guwen_tui_jian_rusume')
                ->where(['guwen_uid'=>$gw_uid,'jobs_id'=>$jobs_id,'order_id'=>$order_id])->count();
            if($tui_user){
                $tui_users=M('guwen_tui_jian_rusume')
                    ->where(['guwen_uid'=>$gw_uid,'jobs_id'=>$jobs_id,'order_id'=>$order_id,'tui_status'=>['in',[0,1]]])->count();
                return $tui_users?0:1;
            }else{
               return  0;
            }
        }
    }
    /**
     * 企业  根据职位id 查找发布的订单  接单情况
     */
    public function fa_bu_zhao_order()
    {
        $job_id = I('jobs_id', 0);
        $fa_bu_o_id=I('order_id',0);
        $page=I('page',1);
        $page_size=I('page_size',10);
        !$job_id && $this->ajaxReturn(1, '职位不存在');
        //查找当前职位的顾问
        $count = M('gu_wen_jie_dan_order')->field('m.user_count,ja.*,m.advisor_level as level,m.advisor_level_name as levelname,m.avatars,m.username')
            ->join('as ja left join qs_members as m on ja.gw_uid=m.uid')
            ->where(['ja.jobs_id' => $job_id,'order_status'=>['not in',[4]]])
            ->count();
        $gu_wens = M('gu_wen_jie_dan_order')->field('m.user_count,ja.*,m.advisor_level as level,m.advisor_level_name as levelname,m.avatars,m.username')
            ->join('as ja left join qs_members as m on ja.gw_uid=m.uid')
            ->where(['ja.jobs_id' => $job_id,'order_status'=>['not in',[4]]])
             ->page($page,$page_size)->select();
        //获取职位类别
      //  var_dump( M('gu_wen_jie_dan_order')->getLastSql());die;
        $jobs_info=M('jobs')->field('duan_qi_money,company_id,trade_cn,category_cn,wage_id,jobs_name,education_cn,experience_cn')->where(['id'=>$job_id])->find();
        if(empty($jobs_info)){
            $this->ajaxReturn(1,'职位不存在');
        }
        $trades =   D('CategoryMajor')->get_major_list();
        //查询订单信息
        $order_info = M('order')->field('is_stop,payment_time,oid,id as order_id')->where(['id' => $fa_bu_o_id,'jobs_id'=>$job_id, 'is_paid' => 2])->order('id desc')->find();
        if (empty($order_info)) {
            $this->ajaxReturn(1, '订单未支付或不存在');
        }
        //查看已选择了多少人
        $count= M('gu_wen_jie_dan_order')->where([
            'jobs_id' => $job_id,
            'comp_uid' => C('visitor.uid'),
            'fa_bu_order'=>$fa_bu_o_id,
            'order_status'=>['neq',4]
        ])->count();
        $order_info['check_count']=$count;
        $order_info['payment_time']=date('Y-m-d',$order_info['payment_time']);
        //jiangqingshan
        // var_dump($order_info);die;
        $trade_list=   D('CategoryMajor')->get_major_list();
        foreach ($gu_wens as $k => $v) {
            //顾问的擅长职位和工程  类别
            $jian_info = M('resume')->field('fullname,intention_jobs,major_cn,good_jobs,good_trade')->where(['uid' => $v['gw_uid']])->find();

            $data= get_guwen_good_trade_job($v['gw_uid'],$trade_list);
            $gu_wens[$k]['intention_jobs']=$data['intention_jobs'];
            $gu_wens[$k]['major_cn']=$data['major_cn'];
            //$gu_wens[$k]['count'] = M('guwen_user')->where(['status' => 0, 'guwen_id' => $v['gw_uid']])->count();
            $gu_wens[$k]['level_log'] = M('guwen_level')->where(['id' => $v['level']])->getField('logo');
            $gu_wens[$k]['sex'] = M('resume')->where(['uid' => $v['gw_uid']])->getField('sex');
            //查询顾问是否接单
            $order_status = M('gu_wen_jie_dan_order')->where(['gw_uid' => $v['gw_uid'], 'fa_bu_order' => $order_info['order_id'],'jobs_id'=>$job_id])->order('id desc')->find();
            $gu_wens[$k]['tui_count']=M('guwen_tui_jian_rusume')->where(['order_id'=>$v['id'],'jobs_id'=>$job_id])->count();
            $gu_wens[$k]['order_status'] = $order_status['order_status'];//0 未接单 1. 已接单 2 已取消
            $gu_wens[$k]['is_comment'] = $order_status['is_comment'];//是否评论 0 未 1 已
          //  $gu_wens[$k]['avatars']=$this->get_site_url().'/data/upload/avatar/'.$v['avatars'];
            $gu_wens[$k]['avatars']=avatar($v['gw_uid']);
            $gu_wens[$k]['order_id']=$fa_bu_o_id;
            $gu_wens[$k]['username']=$jian_info['fullname']?$jian_info['fullname']:$v['username'];
            //查询当前顾问推荐的用户 是否已经全部处理(点了录用 或未录用)
            $gu_wens[$k]['is_chu']=$this->check_is_chuli($v['gw_uid'],$order_status['id'],$job_id);
        }
        $order_info['jl_download_price'] = $this->get_jl_download_price();
         //计算入职薪资
        //$job_info = M('jobs')->where(['id' => $job_id])->find();
        $info=M('jobs')->where(['id'=>$job_id])->find();
        $ru_zhi_info = seal_month_price($info);
     //   var_dump($ru_zhi_info);die;
        $order_info['ru_zhi'] = $ru_zhi_info['ru_zhi'];
        $order_info['ru_zhi_month'] = $ru_zhi_info['ru_zhi_month'];
        $com_info=M('company_profile')->where(['id'=>$jobs_info['company_id']])->getField('logo');
        $order_info['qy_logo']=$com_info? attach($com_info, 'company_logo'): C('qscms_site_domain') . __ROOT__ . '/data/upload/company_logo/default.png';
        $order_info=array_merge($jobs_info,$order_info);
        $wage_info = D('Category')->category_wage();
        if($jobs_info['wage_id']){
            $order_info['wage_cn'] = $wage_info[$jobs_info['wage_id']] . 'k';
        }else{
            $order_info['wage_cn'] = $jobs_info['duan_qi_money'];
        }

        $data['gu_wens'] = $gu_wens;
        $data['total']=$count?(int)$count:0;
        $data['order_info'] = $order_info;
//        //todo 顾问接口情况  添加顾问接单表
//        M('gu_wen_jie_dan_order')->add([
//           'jobs_id'=>$job_id,
//           'fa_bu_order'=>$order_info['id'],
//           'gw_uid'=>0,
//           'order_status'=>0,//0 未接单 1. 已接单 2 已取消
//           'is_comment'=>0,//  是否评论 0 未 1 已
//           'add_time'=>NOW_TIME,
//           'comp_uid'=>0,//企业id
//        ]);
        //var_dump($gu_wens);exit;
        $this->ajaxReturn(0, 'ok', $data);
    }

    /**
     * 企业d订单 接单详情
     */

    public function qiye_jie_dan_detail()
    {
        $order_id=I('order_id',0);
        $jobs_id=I('jobs_id',0);
        $gw_uid=I('gw_uid',0);
        $order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id,'jobs_id'=>$jobs_id,'gw_uid'=>$gw_uid])->find();
        if(empty($order_info)){
            $this->ajaxReturn(1,'订单不存在');
        }
        $page=I('page',1);
        $page_size=I('page_size',10);
        $gw_info=M('members')->field('username,advisor_level,advisor_level_name,avatars,user_count')->where(['uid'=>$gw_uid])->find();
        $trades = $this->get_trade_list_api();
        $jian_info = M('resume')->field('fullname,intention_jobs,major_cn,good_jobs,good_trade')->where(['uid' => $gw_uid])->find();
//        $trades_info = explode(',', $jian_info['good_trade']);
//        $trade_name = '';
//        $trade_name .= $trades[$trades_info[0]];
//        $jobs_cate_info = explode('.', $jian_info['good_jobs']);
//        //$trade_name = substr($trade_name,0,strlen($trade_name)-1);
//        //获取工程类别
//        $jobs_cate_mame_p = D('CategoryJobs')->get_jobs_cache($jobs_cate_info[0]);//职位上级分类
//        $jobs_cate_mame = $jobs_cate_mame_p[$jobs_cate_info[1]];
//        $gw_info['intention_jobs'] = $jobs_cate_mame;
//        $gw_info['major_cn'] = $trade_name;
        $data= get_guwen_good_trade_job($gw_uid,$trades);
        $gw_info['intention_jobs']=$data['intention_jobs'];
        $gw_info['major_cn']=$data['major_cn'];
        //$gu_wens[$k]['count'] = M('guwen_user')->where(['status' => 0, 'guwen_id' => $v['gw_uid']])->count();
        $gw_info['level_log'] = M('guwen_level')->where(['level' => $gw_info['advisor_level']])->getField('logo');
        $gw_info['sex'] = M('resume')->where(['uid' => $gw_uid])->getField('sex');
        $gw_info['order_id']=$order_id;
        $gw_info['jobs_id']=$jobs_id;
        $gw_info['jie_order_id']=$order_info['id'];
        $gw_info['avatars']= attach($gw_info['avatars'], 'avatar');
        $gw_info['order_status']=$order_info['order_status'];
        $gw_info['qy_is_comment']=$order_info['qy_is_comment'];
        $gw_info['avatars']=avatar($gw_info['uid']);
        $gw_info['username']=$jian_info['fullname']?$jian_info['fullname']:$gw_info['username'];
        //推荐的用户
        $fa_bu_info=M('order')->where(['id'=>$order_id])->find();

        $tui_users=M('guwen_tui_jian_rusume')->field('server_money,xishu_rate,oid,add_time,id,resume_uid,desc,comp_uid,tui_status')
            ->where(['guwen_uid'=>$gw_uid,'order_id'=>$order_info['id'],'jobs_id'=>$jobs_id,'fa_type'=>$fa_bu_info['fa_type']])
            ->page($page,$page_size)
            ->select();
        //  var_dump($tui_users);die;
        $count=M('guwen_tui_jian_rusume')->field('guwen_uid,resume_uid,desc,comp_uid')
            ->where(['guwen_uid'=>$gw_uid,'order_id'=>$order_info['id'],'jobs_id'=>$jobs_id,'fa_type'=>$fa_bu_info['fa_type']])->count();
        foreach($tui_users as $k=>$v){
            $user_info=M('members')->where(['uid'=>$v['resume_uid']])->find();
            $jian_info=M('resume')->field('id,fullname,intention_jobs,major_cn,trade_cn,current_cn,education_cn,experience_cn,refreshtime')->where(['uid'=>$v['resume_uid']])->find();
            //       var_dump($jian_info);die;
            $tui_users[$k]['intention_jobs']=$jian_info['intention_jobs'];
            $tui_users[$k]['major_cn']=$jian_info['trade_cn'];
            $tui_users[$k]['sex']=M('resume') ->where(['uid'=>$v['guwen_id']])->getField('sex');
            $tui_users[$k]['avatars']=avatar($user_info);
            //   $tui_users[$k]['avatar']=$user_info['avatars']?$this->get_site_url.'/'.$user_info['avatars']:'';
            $tui_users[$k]['education_cn']=$jian_info['education_cn']?$jian_info['education_cn']:'不限';
            $tui_users[$k]['experience_cn']=$jian_info['experience_cn']?$jian_info['experience_cn']:'不限';
            $tui_users[$k]['time']=daterange(NOW_TIME,$jian_info['refreshtime']);
            $tui_users[$k]['is_down']=$this->check_down_resume($v['resume_uid'],C('visitor.uid'));
            $tui_users[$k]['current_cn']=$jian_info['current_cn'];
            $tui_users[$k]['trade_cn']=$jian_info['trade_cn'];
            $tui_users[$k]['username']=$jian_info['fullname']?$jian_info['fullname']:$user_info['username'];
            $tui_users[$k]['resume_id']=$jian_info['id'];
            $tui_users[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
            $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
            if($v['server_money']>0){
                $ru_zhi_info = seal_month_price($jobs_info);
                $tui_users[$k]['ru_zhi']=$ru_zhi_info['ru_zhi']*$v['xishu_rate'];
                //入职满月费用
                $tui_users[$k]['ru_zhi_month']=$ru_zhi_info['ru_zhi_month']*$v['xishu_rate'];
            }else{
                //入职费用
                $tui_users[$k]['ru_zhi']=0;
                //入职满月费用
                $tui_users[$k]['ru_zhi_month']=0;
            }
        }
        $data['total']=$count;
        $data['gw_info']=$gw_info;
        $data['user_info']=$tui_users;
        $this->ajaxReturn(0,'',$data);
    }

    /**
     * 获取顾问得到的价格 和 平台的金额
     * @param $gw_uid
     * @param $jobs_info
     * @param int $type
     * @param string $server_money
     * @param string $xishu_rate
     * @return mixed
     */
     public function get_job_in_money($gw_uid,$jobs_info,$type=1,$server_money=0,$xishu_rate=0)
     {
         $money_info=seal_month_price($jobs_info);
         //查询顾问的等级信息
        $guwen_info=M('members')->field('advisor_level')->where(['uid'=>$gw_uid])->find();
    //  var_dump($jobs_info);die;
        $level_info=M('guwen_level')->where(['level'=>$guwen_info['advisor_level']])->find();
        if($jobs_info['fa_type']==4){
            if($type==1){
                $money=number_format($money_info['ru_zhi']*$level_info['zhao_ti_rate']/100,2,'.','');
                if($xishu_rate>0){
                    $money=$money*$xishu_rate;
                }
                $price=$money_info['ru_zhi'];
            }else{
                $money=number_format($money_info['ru_zhi_month']*$level_info['zhao_ti_rate']/100,2,'.','');
                if($xishu_rate>0){
                    $money=$money*$xishu_rate;
                }
                $price=$money_info['ru_zhi_month'];
            }
        }else{
            if($type==1){
                $money=number_format($money_info['ru_zhi']*$level_info['zhao_ti_rate']/100,2,'.','');
                $price=$money_info['ru_zhi']/$jobs_info['amount'];
            }else{
                $money=number_format($money_info['ru_zhi_month']*$level_info['zhao_ti_rate']/100,2,'.','');
                $price=$money_info['ru_zhi_month']/$jobs_info['amount'];
            }
        }
        $data['give_money']=$money;
        $data['systerm_get_money']=$price-$money;
        $data['all_money']=$price;
        return $data;
     }


    /**
     * 修改录用状态     0 未处理 1 录用 2未录用 3 未满月离职 4 入职满月
     * @param $username
     * @return bool|mixed
     */
    public function edit_lu_yong_status()
    {
        $uid=I('uid',0);
        $order_id=I('order_id',0);
        $jie_order_id=I('jie_order_id',0);
        $jobs_id=I('jobs_id',0);
        $status=I('status',0);
        if(!in_array($status,[1,2,3,4])){
            $this->ajaxReturn(1,'状态错误');
        }
        $ruzhi_time= I('ruzhi_time','');
        !$uid && $this->ajaxReturn(1,'用户不存在');
        $order_info=M('guwen_tui_jian_rusume')->where(['resume_uid'=>$uid,'order_id'=>$jie_order_id,'jobs_id'=>$jobs_id])->find();
        if(empty($order_info)){
            $this->ajaxReturn(1,'订单不存在');
        }
//          if($order_info['tui_status']>2){
//              $this->ajaxReturn(1,'职位订单已处理');
//          }
        $jie_dan_info=M('gu_wen_jie_dan_order')->where(['id'=>$jie_order_id])->find();
        if(empty($jie_dan_info)){
            $this->ajaxReturn(1,'接单信息不存在');
        }
        if(empty($order_id)){
            $this->ajaxReturn(1,'发布订单不存在');
        }
        // todo 判断录用人数与 发布职位的招聘人数
        $res=check_is_can_tui($jobs_id,$jie_dan_info['comp_uid'],$order_id,$uid);
        //  var_dump($res);die;
//          if(!$res && $status!=2){
//             $this->ajaxReturn(1,'录用人数已满');
//          }
        //判断订单是否停止
        $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
        if($jobs_order['is_stop']){
            $this->ajaxReturn(1,'订单已停止');
        }
        //判断是不是主动推荐人才   是的话就先支付   否则就直接转账
        if($jie_dan_info['fa_type']==4){
            //计算支付金额
            $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
            if($status==2 || $status==3){
                $re=  M('guwen_tui_jian_rusume')->where(['id'=>$order_info['id']])->save([
                    'tui_status'=>$status,
                    'up_time'=>date('Y-m-d H:i:s',time()),
                    // 'ruzhi_time'=>$ruzhi_time,
                ]);
                M('gu_wen_jie_dan_order')->where(['id'=>$jie_order_id])->setField('order_status',3);
                !$re && $this->ajaxReturn(1,'操作失败');
                $this->ajaxReturn(0,'操作成功');
            }else{
                if($order_info['tui_status']==0 && $status==1){//入职
                    //增加顾问余额记录
                    $money_info=get_job_in_money($order_info['guwen_uid'],$jobs_info,1,$order_info['server_money'],$order_info['xishu_rate']);
                }
                //  var_dump($order_info);die;
                if($order_info['tui_status']==1 && $status==4){  //入职满月
                    //增加顾问余额记录
                    $money_info=get_job_in_money($order_info['guwen_uid'],$jobs_info,2,$order_info['server_money'],$order_info['xishu_rate']);
                }
                $data['money']=$money_info['all_money'];
                $data['uid']=$uid;
                $data['jie_order_id']=$jie_order_id;
                $data['jobs_id']=$jobs_id;
                $data['status']=$status;
                $data['ruzhi_time']=$ruzhi_time;
                $this->ajaxReturn(0,'',$data);
            }
        }else{
            $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
            //2 顾问找人才 3 悬赏找人才 4 顾问主动推荐
            if($jie_dan_info['fa_type']==2){
                $desc='顾问找人才';
            }elseif ($jie_dan_info['fa_type']==3){
                $desc='悬赏找人才';
            }elseif ($jie_dan_info['fa_type']==4){
                $desc='推荐的人才';
            }
            if($status==1 && empty($ruzhi_time)){
                $this->ajaxReturn(1,'请选择入职时间');
            }

            if($order_info['tui_status']==0 && $status==1){//入职
                //增加顾问余额记录
                // var_dump($order_info);die;
                $money_info=get_job_in_money($order_info['guwen_uid'],$jobs_info,1);
                //  var_dump($money_info);die;
                $ruzhi_type=1;
                add_guwen_money($order_info['guwen_uid'],$money_info['give_money'],$desc,'service',1,0,$jie_dan_info['fa_type'],0,$jobs_id,$jie_order_id,'入职收入顾问服务费'.$money_info['give_money'],$order_info['comp_uid'],$money_info['all_money'],1,$ruzhi_type,$uid);
            }
            if($order_info['tui_status']==1 && $status==4){  //入职满月
                //增加顾问余额记录
                //   var_dump(222);die;
                $money_info=get_job_in_money($order_info['guwen_uid'],$jobs_info,2);
                $ruzhi_type=2;
                add_guwen_money($order_info['guwen_uid'],$money_info['give_money'],$desc,'service',1,0,$jie_dan_info['fa_type'],0,$jobs_id,$jie_order_id,'入职满月收入顾问服务费'.$money_info['give_money'],$order_info['comp_uid'],$money_info['all_money'],1,$ruzhi_type,$uid);
            }
            //   var_dump(1111);die;
            $re=  M('guwen_tui_jian_rusume')->where(['id'=>$order_info['id']])->save([
                'tui_status'=>$status,
                'up_time'=>date('Y-m-d H:i:s',time()),
                'ruzhi_time'=>$ruzhi_time,
            ]);
            M('gu_wen_jie_dan_order')->where(['id'=>$jie_order_id])->setField('order_status',3);
            !$re && $this->ajaxReturn(1,'操作失败');
            $this->ajaxReturn(0,'操作成功');
        }
    }
    /**
     * 企业取消订单
     */
    public function qiye_cancel_order()
    {
        $order_id=I('order_id',0);
        $jobs_id=I('jobs_id',0);
        $gw_uid=I('gw_uid',0);
        $order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id,'jobs_id'=>$jobs_id,'gw_uid'=>$gw_uid])->find();

        if(empty($order_info)){
            $this->ajaxReturn(1,'订单不存在');
        }
        $row= M('jobs_add_gu_wen')->where([
            'jobs_id' => $jobs_id,
            'gw_uid' => $gw_uid,
            'com_uid' => C('visitor.uid'),
        ])->find();
        if($row){
            M('jobs_add_gu_wen')->where([
                'jobs_id' => $jobs_id,
                'gw_uid' => $gw_uid,
                'com_uid' => C('visitor.uid'),
            ])->setField('status',2);
        }
        $re=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id,'jobs_id'=>$jobs_id,'gw_uid'=>$gw_uid])->setField('order_status',4);
        !$re && $this->ajaxReturn(1,'操作失败');
        $this->ajaxReturn(0,'操作成功');
    }

    /**
     * 我的套餐
     */
    public function my_set_tao()
    {
        $taocan=D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));

        $this->ajaxReturn(0,'',$taocan);
    }
    /**
     * 消费信息
     */
    public function use_xiaofei_log()
    {
        $page=I('page',1);
        $use_type=I('use_type','wxpay');
        $order_type=I('order_type','');
        if($order_type){
            if($order_type=='buy'){
                $where['order_type']=['in',['buy_gcb','buy_taocan']];
            }else{
                $where['order_type']=$order_type;
            }
        }
        $page_size=I('page_size',10);
        $where['use_type']=$use_type;
        $lists=M('member_use_log')->where(['uid'=>C('visitor.uid')])->where($where)->page($page,$page_size)->select();
        $total=M('member_use_log')->where(['uid'=>C('visitor.uid')])->where($where)->count();
        foreach($lists as $k=>$v){
            //发布职位
            if($v['order_type']=='fa_bu' || $v['order_type']=='guwen_server'){
                $order_info=M('order')->where(['jobs_id'=>$v['job_id']])->find();
                $lists[$k]['order_id']=$order_info['id'];
                $lists[$k]['oid']=$order_info['oid'];
            }
            //简历下载
            if($v['order_type']=='resume_down'){
              //  $res_info=M('resume')
            }

        }
        $data['list']=$lists;
        $data['total']=$total;
        $this->ajaxReturn(0,'',$data);
    }

    /**
     * 套餐使用发布情况
     */

    public function get_use_tao_can_fa_bu()
    {
        $zhao_type=I('zhao_type_id',0);
        if(!$zhao_type){
            $this->ajaxReturn(1,'类型错误');
        }
        $where['use_type']='taocan';
        if($zhao_type){
            $where['old_zhao_type_id']=$zhao_type;
        }
        $where['mu.uid']=C('visitor.uid');
        $page=I('page',1);
        $page_size=I('page_size',10);
        $list=M('member_use_log')->field('j.duan_qi_money,j.trade_cn,j.category_cn,district_cn,j.addtime,j.jobs_name,j.experience_cn,j.wage_id,j.audit,j.old_zhao_type_id,j.zhao_type_id,j.zhao_type_name')
            ->join('as mu left join qs_jobs j on mu.job_id = j.id')->where($where)
            ->page($page,$page_size)->select();
       //  var_dump(M('member_use_log')->getLastSql());die;
        $wage_info = D('Category')->category_wage();
        //审核状态 1 通过 2审核中 3 未通过 4 已暂停 5 已到期 6 已暂停
        $count=M('member_use_log')->field('j.trade_cn,j.category_cn,district_cn,j.addtime,j.jobs_name,j.experience_cn,j.education_cn,j.wage_id,j.audit,j.zhao_type_id,j.zhao_type_name')
            ->join('as mu left join qs_jobs j on mu.job_id = j.id')->where($where)->count();
        foreach ($list as $k=> $item) {
            if($item['wage_id']){
                $list[$k]['wage_cn'] = $wage_info[$item['wage_id']] . 'k';
            }else{
                $list[$k]['wage_cn'] = $item['duan_qi_money'];
            }
            $list[$k]['addtime']=date('Y-m-d',$item['addtime']);
            $list[$k]['zhao_type_name']=M('category_pin')->where(['id'=>$item['old_zhao_type_id']])->getField('categoryname');
            $list[$k]['zhao_type_id']=$item['old_zhao_type_id'];
        }
        $data['list']=$list;
        $data['total']=$count;
        $this->ajaxReturn(0,'',$data);
    }

    /**
     * 查看评价
     */
    public function show_comment()
    {
        $type=I('type',0);  //1 顾问 2 企业
        $order_id=I('order_id',0);
        $jobs_id=I('jobs_id',0);
        $order_info=M('gu_wen_jie_dan_order')->where(['id'=>$order_id])->find();
        switch ($type){
            case 1:
                if(empty($order_info) || !$order_info['gw_is_comment']){
                    $this->ajaxReturn(1,'订单状态错误');
                }
                $info=M('comment')->field('id,jobs_id,order_id,xin_zi,lvyue,pei_he')->where(['type'=>$type,'order_id'=>$order_id,'jobs_id'=>$jobs_id])->find();
                break;
            case 2:
                if(empty($order_info) || !$order_info['qy_is_comment']){
                    $this->ajaxReturn(1,'订单状态错误');
                }
                $info=M('comment')->field('id,jobs_id,order_id,xiang_ying,service_taidu,jl_zhi_liang,zhuanye,service_nl')->where(['type'=>$type,'order_id'=>$order_id,'jobs_id'=>$jobs_id])->find();
                break;
            default:
                $info=[];
                break;
        }
        $this->ajaxReturn(0,'',$info);
    }

    /**
     * 获取人才顾问评语模板列表
     */
       public function gwcTpl(){
        $list   = M('GuWenCommentTpl')->field('id, content')->where(['status'=>0])->select();
        $this->ajaxReturn(0, 'ok', $list);
    }

    /**
     * 顾问给人才添加备注
     */
    public function remarksAdd(){
        $uid        = I('uid',0, 'intval');//要给人才备注的UID
        $content    = I('content','', 'trim,badword');//备注信息
        if($this->userinfo['utype'] <> 3) $this->ajaxReturn(1, '你不是人才顾问不能添加备注');

        if(empty($uid)) $this->ajaxReturn(1, '备注的人才UID不能为空');

        $members    = D('Members')->get_user_one(['uid'=>$uid]);
        if(!$members) $this->ajaxReturn(1, '备注的人才不存在');

        if($members['utype'] <> 2) $this->ajaxReturn(1, '当前用户不能添加备注');

        if(empty($content)) $this->ajaxReturn(1, '备注信息不能为空');

        if(M('GuWenResumeRemarks')->where(['gw_uid'=>$this->userinfo['uid'], 'uid'=>$uid, 'content'=>$content])->find()) $this->ajaxReturn(1, '添加的备注已经存在，不能重复添加');

        $info   = M('GuWenResumeRemarks')->add(['gw_uid'=>$this->userinfo['uid'], 'uid'=>$uid, 'content'=>$content, 'addtime'=>time() ]);
        if($info) $this->ajaxReturn(0, 'ok');

        $this->ajaxReturn(1, '添加失败');
    }

    /**
     * 顾问获取一个人才的所有备注
     */
    public function remarksList(){
        $uid        = I('uid',0, 'intval');//要给人才备注的UID
        if($this->userinfo['utype'] <> 3) $this->ajaxReturn(1, '你不是人才顾问不能获取备注');

        if(empty($uid)) $this->ajaxReturn(1, '备注的人才UID不能为空');

        $members    = D('Members')->get_user_one(['uid'=>$uid]);
        if(!$members) $this->ajaxReturn(1, '备注的人才不存在');

        if($members['utype'] <> 2) $this->ajaxReturn(1, '当前用户非人才角色不能获取备注');

        $list   = M('GuWenResumeRemarks')->field('id, content, addtime')->where(['gw_uid'=>$this->userinfo['uid'], 'uid'=>$uid])->select();
        foreach($list as &$val){
            $val['addtime'] = date('Y-m-d', $val['addtime']);
        }
        $this->ajaxReturn(0, 'ok', $list);
    }

    /**
     * remarksDel
     * 删除备注

     * 删除一个人才的备注信息

     * @access public

     * @param string    $id (必填：是)
     * @since

     * @return json

     */
    public function remarksDel(){
        $id         = I('post.id', 0, 'intval');
        if(empty($id)){
            $this->ajaxReturn(1, '删除的教育经历ID不能为空');
        }
        $remarks  = M('GuWenResumeRemarks')->where(['id'=>$id, 'gw_uid'=> $this->userinfo['uid']])->find();
        if(empty($remarks)){
            $this->ajaxReturn(1, '删除的记录不存在');
        }

        if(M('GuWenResumeRemarks')->delete($id)){
            $this->ajaxReturn(0, '删除成功');
        }

        $this->ajaxReturn(1, '删除失败');
    }

    /**
     * 顾问的余额激励
     */

    public function gw_money_log()

    {

//         $where['gw_uid']=C('visitor.uid');
//        $where['add_type']=1;
//        $where['id']=['gt',6];
//       $res= M('guwen_money_log')->field('add_time,money,desc')->where($where)->order('id desc')->select();
//
//        var_dump($res);die;
//      //  var_dump(M('guwen_money_log')->where($where)->sum('money'));die;
        $type=I('type',1);
        $order_type=I('order_type','');
        $down_type=I('down_type','');
        $fa_type=I('fa_type',0);
        $where['type']=$type;
        $where['gw_uid']=C('visitor.uid');
        if($order_type){
            $where['order_type']=$order_type;
        }
        if($down_type){
            $where['down_type']=$down_type;
        }
        if($fa_type){
            $where['fa_type']=$fa_type;
        }
        $where['add_type']=1;
        $page=I('page',1);
        $page_size=I('page_size',10);
        if($order_type=='withdraw'){
            $list=M('guwen_withdraw_list')->field('id,add_time,pay_money as money,status')->where(['gw_uid'=>C('visitor.uid')])->page($page,$page_size)->order('id desc')->select();
            $count=M('guwen_withdraw_list')->where(['gw_uid'=>C('visitor.uid')])->count();
            foreach ($list as $k=>$v){
                $list[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
                if($v['status']==0){
                 $list[$k]['desc']='提现处理中';
                }elseif ($v['status']==1){
                 $list[$k]['desc']='提现成功';
                }elseif ($v['status']==2){
                 $list[$k]['desc']='提现驳回';
                }
            }
        }else{
            $list=M('guwen_money_log')->field('id,add_time,money,desc')->where($where)->page($page,$page_size)->order('id desc')->select();
            $count=M('guwen_money_log')->where($where)->count();
            foreach($list as $k=>$v){
                $list[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
            }
        }

        $data['list']=$list;
        $data['total']=$count;
        $this->ajaxREturn(0,'',$data);
    }

    /**
     * 统计职位状态的总数
     */
    public function get_jobs_status_count()
    {
        //审核状态 1 通过 2审核中 3 未通过 4 已暂停 5 已到期
      $fa_bu_status_count=$this->_get_jobs_status_count(1);
      $shen_count=$this->_get_jobs_status_count(2);
      $wei_count=$this->_get_jobs_status_count(3);
      $zan_count=$this->_get_jobs_status_count(4);
      $out_count=$this->_get_jobs_status_count(5);
      $data['fa_bu_count']=$fa_bu_status_count;
      $data['shen_count']=$shen_count;
      $data['wei_count']=$wei_count;
      $data['zan_count']=$zan_count;
      $data['out_count']=$out_count;
      $this->ajaxReturn(0,'ok',$data);
    }

    protected function _get_jobs_status_count($status)
    {

     $count= M('Jobs')->where(['audit'=>$status,'uid'=>C('visitor.uid'),'zhao_type_id'=>['in',[1,2,3,4]],'fa_type'=>['in',[1,2,3,4]]])->count();

     return $count?(int)$count:0;
    }

    /**
     * 顾问推荐的简历
     */

    public  function gw_tui_resume_list()
    {
        $page=I('page',1);
        $page_size=I('page_size',10);
        $uid=C('visitor.uid');
        $where['gj.fa_type']=4;
        $where['gj.comp_uid']=$uid;
        if(I('jobs_id')){
            $where['gj.jobs_id']=I('jobs_id');
        }
      $uids=M('gu_wen_jie_dan_order')->join('as gj left join qs_guwen_tui_jian_rusume as gt on gj.id=gt.order_id')->where($where)->getField('gj.id,gt.resume_uid',true);
      //查询简历
        $list=[];
        $count=0;
        if($uids){
            $list=M('resume')->join('as r left join qs_members as m on r.uid=m.uid')
                ->field('r.sex,m.avatars,r.fullname,m.username,m.uid,r.trade_cn,intention_jobs,r.current_cn,r.refreshtime,r.experience_cn')
                ->where(['r.uid'=>['in',$uids]])->page($page,$page_size)->select();
            $count=M('resume')->join('as r left join qs_members as m on r.uid=m.uid')
                ->field('r.sex,m.avatars,r.fullname,m.username,m.uid,r.trade_cn,intention_jobs,r.current_cn,r.refreshtime,r.experience_cn')
                ->where(['r.uid'=>['in',$uids]])->count();
            foreach($list as $k=>$v){
                //查询 用户的 职位推荐表
                $tui_info=M('guwen_tui_jian_rusume')->where(['company_uid'=>$uid])->getField('jobs_id',true);
                $names=M('jobs')->field('id,jobs_name,uid')->where(['id'=>['in',$tui_info],'audit'=>1])->select();
                $name='';
                //   var_dump($names);die;
                foreach ($names as $k1=>$v1){
                    $name.=$v1['jobs_name'].',';
                }
                $name=substr($name,0,strlen($name)-1);
                $list[$k]['jobs_name']=$name;
                $list[$k]['refreshtime']=daterange(NOW_TIME,$v['refreshtime']);
                $list[$k]['avatars']=attach($v['avatars'],'avatars');
            }
        }

       $data['list']=$list;
       $data['total']=$count;
      // var_dump(M('gu_wen_jie_dan_order')->getLastSql());
      $this->ajaxReturn(0,'ok',$data);
    }

    /**
     * 暂停职位
     */
     public function zanting_jobs()
     {
         $jobs_id=I('jid',0);
         !$jobs_id && $this->ajaxReturn(1,'职位不存在');
         $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
         if(empty($jobs_info)){
             $this->ajaxReturn(1,'职位不存在');
         }
         if($jobs_info['audit']==4){
             $this->ajaxReturn(1,'此职位已是暂停状态');
         }
         $setsqlarr=$jobs_info;
         $setsqlarr['topclass']=explode(',',$setsqlarr['topclass']);
         $setsqlarr['category']=explode(',',$setsqlarr['category']);
         $city_info=explode('.',$setsqlarr['district']);
         //  var_dump($city_info);
         $setsqlarr['district']=$city_info[2];
         $setsqlarr['audit']=4;
         $setsqlarr['id']=$jobs_id;
         $rst = D('Jobs')->edit_jobs($setsqlarr, C('visitor'));
        //  var_dump($rst);die;
       //  if($rst[''])
         $this->ajaxReturn(0, '操作成功！' );
       //  var_dump($rst);

     }

    /**
     * 删除职位
     */

    public function jobs_delete()
    {
        $yid = I('y_id',0);
        if (IS_POST) {
            if (!$yid) {
               $this->ajaxReturn(0, '请选择职位！');
            }
            $perform_type = 'delete';
            $rst = D('Jobs')->jobs_perform(array('yid' => $yid, 'perform_type' => $perform_type, 'user' => C('visitor')));
            $return_url = I('request.list_type', 0, 'intval') == 0 ? U('jobs_list') : U('jobs_list', array('type' => 1));
            if ($rst['state'] == 1) {
                 $this->ajaxReturn(0, '操作成功！', $return_url);
            } else {
               $this->ajaxReturn(1, $rst['error'], $return_url);
            }
        }
    }

    /**
     * 重新发布职位
     */

    public function again_fa_jobs()
    {
        $this->_cominfo_flge();
        if (!$this->cominfo_flge) {
            $this->ajaxReturn(1, '为了达到更好的招聘效果，请先完善您的企业资料！');
        }
        //对座机进行分隔
        $telarray = explode('-', $this->company_profile['landline_tel']);

        $setmeal = D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));

        // 统计有效职位数
//        $jobs_num = D('Jobs')->where(array('uid' => C('visitor.uid')))->count();
//        $jobs_num_tmp = D('JobsTmp')->where(array('uid' => C('visitor.uid'), 'display' => 1))->count();
//        if ($setmeal[''] + $jobs_num_tmp >= $setmeal['jobs_meanwhile'] && I('request.id', 0, 'intval') == 0) {
//                $this->ajaxReturn(1, '当前显示的职位已经达到最大限制，请升级服务套餐!');
//        }
        $zhao_type = I('zhao_type', 0);
        if (!in_array($zhao_type, [1, 2, 3, 4, 5])) {
            $this->ajaxReturn(1, '类型错误');
        }
        // 保存 POST 数据
        // 插入职位信息
        $data = JobsInfoModel::check_fabu_params();
        if ($data['status']) {
            $this->ajaxReturn(1, $data['msg']);
        }
        $jobs_info = '';
        $setsqlarr = $data['data'];
        if ($id = I('post.id', 0, 'intval')) {
            $setsqlarr['id'] = $id;

            $setsqlarr['addtime'] = time();
            $jobs_info = D('Jobs')->find($id);
            $setsqlarr['is_again']=$setsqlarr['again_count']+1;
            $setsqlarr['is_again']=1;
            if (!$jobs_info) {
                $jobs_info = D('JobsTmp')->find($id);
            }
            $name = 'edit_jobs';

            S('jobs_info',$jobs_info);
        } else {
            $name = 'add_jobs';
            //分站信息调取
            if (C('subsite_info') && C('subsite_info.s_id') != 0) {
                $setsqlarr['subsite_id'] = C('subsite_info.s_id');
            }
            //end
        }
        $setsqlarr['setmeal_deadline'] = $setmeal['endtime'];
        $setsqlarr['deadline'] = $setsqlarr['setmeal_deadline'];
        $setsqlarr['setmeal_id'] = $setmeal['setmeal_id'];
        $setsqlarr['setmeal_name'] = $setmeal['setmeal_name'];
        $setsqlarr['uid'] = C('visitor.uid');
        $setsqlarr['company_id'] = $this->company_profile['id'];
        $setsqlarr['company_addtime'] = $this->company_profile['addtime'];
        $setsqlarr['companyname'] = $this->company_profile['companyname'];
        $setsqlarr['company_audit'] = $this->company_profile['audit'];
        C('apply.Sincerity') && $setsqlarr['famous'] = $this->company_profile['famous'];
        if (!$id) {
            $setsqlarr['audit'] = 2;
        } else {
            if ($this->company_profile['audit'] == 1) {
                if (C('qscms_audit_verifycom_editjob') == '-1') {
                    if ($jobs_info['audit'] == 3) {
                        $setsqlarr['audit'] = 2;
                    } else {
                        $setsqlarr['audit'] = $jobs_info['audit'];
                    }
                } else {
                    $setsqlarr['audit'] = C('qscms_audit_verifycom_editjob');
                }
            } else {
                if (C('qscms_audit_unexaminedcom_editjob') == '-1') {
                    if ($jobs_info['audit'] == 3) {
                        $setsqlarr['audit'] = 2;
                    } else {
                        $setsqlarr['audit'] = $jobs_info['audit'];
                    }
                } else {
                    $setsqlarr['audit'] = C('qscms_audit_unexaminedcom_editjob');
                }
            }
            $setsqlarr['audit']=2;
        }
        $rst = D('Jobs')->$name($setsqlarr, C('visitor'));
        if ($rst['state'] == 0) {
            $this->ajaxReturn(0, $rst['error']);
        }
        if ($jobs_info) {
            if ($setsqlarr['audit'] != $jobs_info['audit']) {
                switch ($setsqlarr['audit']) {
                    case 1:
                        $audit_str = '审核通过';
                        break;
                    case 2:
                        $audit_str = '审核中';
                        break;
                    case 3:
                        $audit_str = '审核未通过';
                        break;
                    default:
                        $audit_str = '';
                        break;
                }
                if ($audit_str) {
                    $auditsqlarr['jobs_id'] = $jobs_info['id'];
                    $auditsqlarr['reason'] = '自动设置';
                    $auditsqlarr['status'] = $audit_str;
                    $auditsqlarr['addtime'] = time();
                    $auditsqlarr['audit_man'] = '系统';
                    M('AuditReason')->data($auditsqlarr)->add();
                }
            }
        } else {
            switch ($setsqlarr['audit']) {
                case 1:
                    $audit_str = '审核通过';
                    break;
                case 2:
                    $audit_str = '';
                    break;
                case 3:
                    $audit_str = '审核未通过';
                    break;
                default:
                    $audit_str = '';
                    break;
            }
            if ($audit_str) {
                $auditsqlarr['jobs_id'] = $rst['id'];
                $auditsqlarr['reason'] = '自动设置';
                $auditsqlarr['status'] = $audit_str;
                $auditsqlarr['addtime'] = time();
                $auditsqlarr['audit_man'] = '系统';
                M('AuditReason')->data($auditsqlarr)->add();
            }
        }
        if (C('qscms_jobs_display') == 2) {
            baidu_submiturl(url_rewrite('QS_jobsshow', array('id' => $rst['id'])), 'addjob');
        }

        $this->ajaxReturn(0,  '重新发布成功！', array('url' => U('company/jobs_list'), 'insertid' => $rst['id']));
    }

    /**
     * 修改招聘结束时间
     * @param $zhao_end_time
    * @param $order_info
   */
   public function edit_zhao_end_time($zhao_end_time=[],$order_info=[])
   {
       //已经支付成功了 那就修改is_edit 为0  is_shou  为 o   is_again 为0

       //判断是否有套餐
       $zhao_end_time='';
       $order_info=M('order')->where(['id'=>176])->find();
       $taocan_info=D('MembersSetgcb')->get_user_setmeal($order_info['uid']);
       $jobs_info=M('jobs')->where(['id'=>$order_info['jobs_id']])->find();
      // var_dump($jobs_info);die;
       if($taocan_info && empty($zhao_end_time)){
           if(!$jobs_info['is_edit']){
               M('jobs')->where(['id'=>$order_info['jobs_id']])->setField('zhao_end_time',date('Y-m-d',strtotime('+1 year')));
           }else{
               if($jobs_info['is_shou']){
                   M('jobs')->where(['id'=>$order_info['jobs_id']])->setField('zhao_end_time',date('Y-m-d',strtotime('+1 year')));
               }
           }
       }
       if(empty($zhao_end_time) && empty($zhao_end_time)){
           //判断发布类型
           if(!$jobs_info['is_edit']) {
               if ($jobs_info['old_zhao_type_id'] == 1) { //常规 6个月
                   M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+6 month')));
               } elseif ($jobs_info['old_zhao_type_id'] == 2) {//急招   3个月
                   M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+3 month')));
               } elseif ($jobs_info['old_zhao_type_id'] == 3) {//短期  3个月
                   M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+3 month')));
               } elseif ($jobs_info['old_zhao_type_id'] == 3) {//项目专场 6个月
                   M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+6 month')));
               }
                 if($jobs_info['is_again']){
                     M('jobs')->where(['id'=>$jobs_info['id']])->setField('is_again',0);
                 }
           }else{
               if($jobs_info['is_shou']){
                   if ($jobs_info['old_zhao_type_id'] == 1) { //常规 6个月
                       M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+6 month')));
                   } elseif ($jobs_info['old_zhao_type_id'] == 2) {//急招   3个月
                       M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+3 month')));
                   } elseif ($jobs_info['old_zhao_type_id'] == 3) {//短期  3个月
                       M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+3 month')));
                   } elseif ($jobs_info['old_zhao_type_id'] == 3) {//项目专场 6个月
                       M('jobs')->where(['id' => $order_info['jobs_id']])->setField('zhao_end_time', date('Y-m-d', strtotime('+6 month')));
                   }
                   M('jobs')->where(['id'=>$jobs_info['id']])->setField('is_shou',0);
               }
               M('jobs')->where(['id'=>$jobs_info['id']])->setField('is_edit',0);
           }
       }
       if($zhao_end_time || ($taocan_info && $zhao_end_time)){
           if(!$jobs_info['is_edit']){
               M('jobs')->where(['id'=>$order_info['jobs_id']])->setField('zhao_end_time',$zhao_end_time);
           }else{
               if($jobs_info['is_shou']){
                   M('jobs')->where(['id'=>$order_info['jobs_id']])->setField('zhao_end_time',$zhao_end_time);
                   M('jobs')->where(['id'=>$jobs_info['id']])->setField('is_shou',0);
               }
               M('jobs')->where(['id'=>$jobs_info['id']])->setField('is_edit',0);
           }
       }
    //   var_dump( M('jobs')->getLastSql());die;

   }

    /**
     * 我的客服
     */

   public function get_ke_fu_info()
   {
       $res=M('config')->where(['name'=>['in',['kefu_wx_num','kf_weixin_img']]])->select();
       $data=[];
       foreach($res as $k=>$v){
           $data[$v['name']]=$v['value'];
       }
       $data['kf_weixin_img']=attach(C('qscms_kf_weixin_img'),'resource');

       $this->ajaxReturn(0,'ok',$data);
   }


    /**
     * 获取搜索简历的分类数据
     */

    public function get_search_cate()
    {
        $language_level = D('Category')->category_get_by_alias('QS_language_level', 'language_level'); //语言等级
     // $experience_list = $this->get_experience_list(); //工作经验
        $education_list = $this->get_education_list();//学历
        $nature_list = $this->get_nature_list();//工作性质
        $trade_list = D('CategoryMajor')->get_engineering_and_children();//工程类别
        $qs_wage = D('Category')->category_wage_copy();//薪资
        $city_list = D('CategoryDistrict')->get_city_and_children(0);//城市
        $jobs_cate = D('CategoryJobs')->get_all_cate();//职位分类
//        $jobtag = D('Category')->category_get_by_alias('QS_jobtag', 'jobtag');//福利标签
//        $zhao_type = $this->get_type_list_copy();//发布的招聘类型
//        $work_time = D('Category')->category_get_by_alias('QS_work_time', 'work_time'); //工作时间
        $dao_gang_type = D('Category')->category_get_by_alias('QS_dutytime ', 'dutytime_dao'); //到岗时间
        $language = D('Category')->category_get_by_alias('QS_language', 'language'); //语言
        $current_list   =   D('Category')->category_current();  //求职状态
        $data['other'] = [
            [
                'name' => '职位类别',
                'data' => $jobs_cate,
                'value' => 'jobcategory',
            ],
            [
                'name' => '工程类别',
                'data' => $trade_list,
                'value' => 'trade',
            ],
            [
                'name' => '居住地',
                'data' => $city_list,
                'value' => 'residence',
            ],
//            [
//                'name' => '期望工作地',
//                'data' => $city_list,
//                'value' => 'citycategory',
//            ],
//            [
//                'name' => '工作经验',
//                'data' => $experience_list,
//                'value' => 'experience'
//            ],
            [
                'name' => '学历要求',
                'data' => $education_list,
                'value' => 'education'
            ],
            [
                'name' => '工作性质',
                'data' => $nature_list,
                'value' => 'nature'
            ],
            [
                'name' => '薪资',
                'data' => $qs_wage,
                'value' => 'wage',
            ],
            [
                'name' => '语言',
                'data' => $language,
                'value' => 'language',
            ],
            [
                'name' => '语言等级',
                'data' => $language_level,
                'value' => 'language_level',
            ],
            [
                'name' => '求职状态',
                'data' => $current_list,
                'value' => 'current',
            ],
            [
                'name' => '到岗时间',
                'data' => $dao_gang_type,
                'value' => 'dao_gang',
            ],
        ];
        $this->ajaxReturn(0, '', $data);
    }

    /**
     * 获取顾问的手机号和余额
     */

    public function get_gw_money_or_tel()
    {
      $user_info=$this->userinfo;
      $data['money']=$user_info['money'];
      $data['uid']=$user_info['uid'];
      $data['mobile']=$user_info['mobile'];
      $this->ajaxReturn(0,'ok',$data);
    }

    /**
     * 顾问提现
     */

    public function guwen_withdraw()
    {
        $money=I('money',0);
        $code=I('code',0);
        //判断上次提现时间
        $re=M('guwen_withdraw_list')->where([
            'gw_uid'=>C('visitor.uid')])->order('id desc')->find();
        !$money && $this->ajaxReturn(1,'请输入提现金额');
        //验证验证码
        $mobile = I('mobile', 0);
          if(!I('code', 0, 'intval')){
              $this->ajaxReturn(1, '验证码不存在或已过期');
          }
//        if (!S('mwithdraw_' . $mobile)) {
//            $this->ajaxReturn(1, '验证码不存在或已过期');
//        }

        if (S('mwithdraw_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
            $this->ajaxReturn(1, '验证码不存在或已过期');
        }
        S('mwithdraw_' . $mobile, null);
        $wxcode         = I('post.wxcode','','trim,badword');
        if (empty($wxcode)) $this->ajaxReturn(1, '微信wxcode不能为空');
        $openId     = wxOpenId($wxcode, $this->userinfo['uid']);


        if (!empty($openId['status'])) $this->ajaxReturn(1, '微信openId获取失败');
//       if(empty($openid)){
//           $this->ajaxReturn(1,'请填写openid');
//       }
        if(empty($openId['data'])){
            $this->ajaxReturn(1,'微信openId获取失败');
        }
  //   var_dump($openId);die;
        $openid=$openId['data'];
        if($money<0){
            $this->ajaxReturn(1,'金额输入错误');
        }
        $info=M('members')->where(['uid'=>C('visitor.uid')])->find();
        if($info['money']<$money){
            $this->ajaxReturn(1,'余额不足');
        }
        $re=M('guwen_withdraw_list')->add([
           'gw_uid'=>C('visitor.uid'),
           'all_money'=>$money,
           'rate'=>0,//手续费
           'pay_money'=>$money,//时间到账金额
           'status'=>0,//0 待审核   1 通过 2 拒绝
            'pay_time'=>0,
            'ti_type'=>1,//1 微信  2 线下
            'add_time'=>NOW_TIME,
            'openid'=>$openid,
        ]);
        if($re){
           //减少用户余额
            $res= M('members')->where(['uid'=>C('visitor.uid')])->setDec('money',$money);

            if($res){
                add_guwen_money(C('visitor.uid'),$money,'提现','withdraw',2,0,0,0,0,$re,'提现');
                $this->ajaxReturn(0,'申请提现成功,请等待审核');
            }else{
                $this->ajaxReturn(1,'修改余额失败');
            }

        }else{
            $this->ajaxReturn(1,'申请失败，请重试');
        }
    }

    /**
     * 我的等级记录
     */
    public function gw_level_log()
    {

        $page=I('page',1);
        $page_size=I('page_size',10);
        $list=M('guwen_level_log')->where(['gw_uid'=>C('visitor.uid')])->page($page,$page_size)->order('id desc')->select();
        foreach ($list as $k=>$v){
            $list[$k]['shou_quan_time']=date('Y-m-d',$v['shou_quan_time']);
        }
        $data['list']=$list;

        $data['current_level']=$this->userinfo['advisor_level_name'];
        $this->ajaxReturn(0,'ok',$data);
    }

    /**
     * 验证经历下载次数
     */
    public function check_down_count()
    {
        $taocan_info=D('MembersSettaocan')->get_user_setmeal(C('visitor.uid'));
        $is_mian_count=0;
        $count = D('CompanyDownResume')->get_down_count(C('visitor.uid'));
        if($count>3){
            $is_mian_count=0;
        }else{
            $is_mian_count=3-$count;
        }
        if(empty($taocan_info)){
            //检查之前的下载次数
           $is_has=0;
         }else{
            $is_has=1;
            $sheng_yu_count=$taocan_info['jl_down_num'] - $taocan_info['jl_yi_down_num'];
         }
        $data['is_has']=$is_has;
        $data['is_mian_count']=$is_mian_count;
        $data['sheng_yu_count']=$sheng_yu_count;
        $this->ajaxReturn(0,'ok',$data);
    }

    /**
     * 求职状态修改
     */

   public function edit_current_status()
   {
       $current_id=I('current_id',0);
       !$current_id && $this->ajaxReturn(1,'请选择求职状态');
        $resume_info=M('resume')->where(['uid'=>C('visitor.uid')])->find();
       if(empty($resume_info)){
           $this->ajaxReturn(1,'简历信息不存在，请先填写简历');
       }
       $data['current']=$current_id;
       $category       = D('Category')->category_current_api();

       $data['current'] && $data['current_cn']      = $category[$data['current']];//求职状态
       $resume_info['current']=$current_id;
       $resume_info['current_cn']=$data['current_cn'];
       $rst = D('Resume')->save_wx_resume($data, $resume_info['id'], C('visitor'));
       //var_dump($rst);die;
     //  sleep(1);
       if ($rst['state']) $this->ajaxReturn(1, '操作失败，请重试！');
    //   $res=M('resume')->where(['id'=>$resume_info['id']])->save($data);
      // var_dump($rst);die;
//       if($res!==false){
//           write_members_log(C('visitor'), 'resume', '保存求职状态信息（简历id：' . $resume_info['id'] . '）', false, array('resume_id' => $resume_info['id']));
//           $this->ajaxReturn(0, '操作成功！');
//       }else{
           $this->ajaxReturn(0,'操作成功');
//       }
   }


    public function refund()
   {
       $jobs_id=97;
       $order_info=M('order')->where(['jobs_id'=>$jobs_id]) ->find();
      //判断发布类型
       if(in_array($order_info['fa_type'],[2,3])){
           return true;
       }
       if($order_info['is_refund']){
          return true;
      }
       if(empty($order_info)){
            return true;
       }
       if($order_info['is_refund']){
           return true;
       }
       //var_dump($order_info);die;
       $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
      // var_dump($jobs_info);die;
       //判断支付类型、
       if($order_info['payment']=='remittance'){
          return true;
       }elseif ($order_info['payment']=='gcb'){
          $this->check_refund_gcb($jobs_info,$order_info);
       }elseif ($order_info['payment']=='wxpay'){
          //todo 微信退款
       }elseif ($order_info['payment']=='use_taocan'){
          $this->check_refund_taocan($jobs_info,$order_info);
       }
   }
    /**
     * 使用套餐支付 增加发布次数
     * @param $jobs_info
     * @param $order_info
     */
    public function check_refund_taocan($jobs_info,$order_info)
   {
       //判断是否存在套餐
       $taocan=D('MembersSettaocan')->get_user_setmeal($order_info['uid']);
       if($taocan){
           $re=0;
          //判断 发布职位招聘类型
           $city_ids=explode(',',$jobs_info['fa_bu_ids']);
           $count=count($city_ids);
           if($jobs_info['old_zhao_type_id']==1){   //常规
               $re=  M('members_settaocan')->where(['uid'=>$jobs_info['uid']])->setDec('cg_yi_fa_count',$count);
           }elseif ($jobs_info['old_zhao_type_id']==2){//急招
               $re=  M('members_settaocan')->where(['uid'=>$jobs_info['uid']])->setDec('ji_zhao_yi_fa_count',$count);
           }elseif ($jobs_info['old_zhao_type_id']==3){//短期
               $re=  M('members_settaocan')->where(['uid'=>$jobs_info['uid']])->setDec('duan_qi_yi_fa_count',$count);
           }elseif ($jobs_info['old_zhao_type_id']==4){//项目
               $re=  M('members_settaocan')->where(['uid'=>$jobs_info['uid']])->setDec('xmzc_yi_fa_count',$count);
           }
           if($re){
               M('order')->where(['id'=>$order_info['id']])->save([
                  'is_refund'=>1,
                  'refund_time'=>NOW_TIME,
               ]);
               M('member_use_log')->add([
                   'order_type'=>'fa_bu',
                   'use_type'=>'taocan',
                   'price'=>0,
                   'rid'=>0,
                   'job_id'=>$jobs_info['id'],
                   'uid'=>$jobs_info['uid'],
                   'desc'=>'职位【'.$jobs_info['jobs_name'].'】审核拒绝',
                   'add_type'=>2,
                   'add_time'=>date('Y-m-d H:i:s',NOW_TIME),
               ]);
           }

       }
   }

    /**
     * 使用工程币支付退款
     * @param $jobs_info
     * @param $order_info
     */
     public function check_refund_gcb($jobs_info,$order_info)
    {
    //添加 用户的工程币 余额
       $taocan=M('MembersSetgcb')->get_user_setmeal($order_info['uid']);
        if($taocan){
          $re=M('members_setgcb')->where(['uid'=>$jobs_info['uid']])->setField('use_num',$order_info['pay_amount']);
          if($re){
              M('order')->where(['id'=>$order_info['id']])->save([
                  'is_refund'=>1,
                  'refund_time'=>NOW_TIME,
              ]);
              M('member_use_log')->add([
                  'order_type'=>'fa_bu',
                  'use_type'=>'taocan',
                  'price'=>0,
                  'rid'=>0,
                  'job_id'=>$jobs_info['id'],
                  'uid'=>$jobs_info['uid'],
                  'desc'=>'职位【'.$jobs_info['jobs_name'].'】审核拒绝',
                  'add_type'=>2,
                  'add_time'=>date('Y-m-d H:i:s',NOW_TIME),
              ]);
          }
        }
    }

    /**
     * myClient
     * 我的客户

     * 我推荐的客户和我合作的客户
     * @access public

     * @param int $type 类型 0我推荐的 1我合作的
     * @param int $page 当前页数
     * @param int $pageSize 叶大小
     */

    public function myClient(){
        $type       = I('post.type', 0, 'intval');
        $page       = I('post.page', 1, 'intval');
        $pageSize   = I('post.page_size', 10,'intval');

        $user       = $this->userinfo;
        $tableName  = C('DB_PREFIX').'company_profile';

        if(empty($type)) {
            $field  = 'c.id as id, c.uid as uid, c.companyname as companyname, c.logo as logo, c.addtime as addtime, c.nature as nature, c.nature_cn as nature_cn, c.scale as scale, c.scale_cn as scale_cn';
            $count  = M("GuwenUser as g")->join('right join ' . $tableName . ' as c on g.uid=c.uid')->where(['g.status' => 0, 'g.guwen_id' => $user['uid']])->count();
            $totalPage = ceil($count / $pageSize);
            $result = M("GuwenUser as g")->field($field)->join('right join ' . $tableName . ' as c on g.uid=c.uid')->where(['g.status' => 0, 'g.guwen_id' => $user['uid']])->page($page, $pageSize)->select();
             foreach($result as &$val){
                $money  =  M('Order')->where(['uid'=>$val['uid'],'is_paid'=>2])->sum('pay_amount');
                $val['logo']    = $val['logo'] ? attach($val['logo'], 'company_logo') : attach('default.png', 'company_logo');
                $val['money']   = $money ? $money : '0';
                $val['addtime'] = date('Y-m-d',$val['addtime']);
            }
        }else{
            //distinct去重复记录 只能放在第一个去重字段前面
            /*$field  = 'distinct c.id as id, g.gw_uid as gw_uid, c.uid as uid, c.companyname as companyname, c.logo as logo, c.addtime as addtime, c.nature as nature, c.nature_cn as nature_cn, c.scale as scale, c.scale_cn as scale_cn';
            $count  = count(M("GuWenJieDanOrder as g")->field($field)->join('left join ' . $tableName . ' as c on g.comp_uid=c.uid')->where(['g.gw_uid' => $user['uid']])->select());
            $totalPage = ceil($count / $pageSize);
            $result = M("GuWenJieDanOrder as g")->field($field)->join('left join ' . $tableName . ' as c on g.comp_uid=c.uid')->where(['g.gw_uid' => $user['uid']])->page($page, $pageSize)->select();*/

            //以上注释二选一
            $field  = 'c.id as id, g.gw_uid as gw_uid, c.uid as uid, c.companyname as companyname, c.logo as logo, c.addtime as addtime, c.nature as nature, c.nature_cn as nature_cn, c.scale as scale, c.scale_cn as scale_cn';
            $count  = M("GuWenJieDanOrder as g")->join('right join ' . $tableName . ' as c on g.comp_uid=c.uid')->where(['g.gw_uid' => $user['uid']])->count('distinct g.comp_uid');
            $totalPage = ceil($count / $pageSize);
            $result = M("GuWenJieDanOrder as g")->field($field)->join('right join ' . $tableName . ' as c on g.comp_uid=c.uid')->where(['g.gw_uid' => $user['uid']])->group('g.comp_uid')->page($page, $pageSize)->select();
             foreach($result as &$val){
                $money  =  M('GuwenMoneyLog')->where(['gw_uid'=>$val['gw_uid'],'comp_uid'=>$val['uid'],'type'=>1])->sum('money');
                $val['logo']    = $val['logo'] ? attach($val['logo'], 'company_logo') : attach('default.png', 'company_logo');
                $val['money']   = $money ? $money : '0';
                $val['addtime'] = date('Y-m-d',$val['addtime']);
            }
        }
        $data   = [
            'totalPage' => $totalPage,
            'list'      => $result,
            'count'     => $count,
        ];

        $this->ajaxReturn(0, 'ok', $data);

    }

    public function check_withdraw()
    {
       $data=[];
       $data['type']='wxpay';
       $data['openid']='oObsr408s2-fWCI0imDiGkbhIhyM';
       $data['partner_trade_no']=1;
       $data['amount']=0.01;
       $res=  D('Payment')->withdraw_pay($data);

     var_dump($res);die;
    }

    /**
     * 修改招聘结束时间到期职位的状态
     */
       public function check_jobs_end_time()
       {
           $list=M('jobs')->field('id,jobs_name')->where(['audit'=>['in',[1,2,3,4]],'zhao_end_time'=>['lt',date('Y-m-d')]])->limit(100)->select();
            // var_dump(M('jobs')->getLastSql());
            //  var_dump($list);
           foreach($list as $k=>$v){
             $res= M('jobs')->where(['id'=>$v['id']])->setField('audit',5);
           }
           $this->ajaxReturn(0,'ok',$res);
       }

    /**
     * 保证金订单详情
     */

    public function service_detail()
    {
        $order_id=I('order_id');
        !$order_id && $this->ajaxReturn(1,'订单错误');
        $jie_order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->select();
        $order_info=M('order')->field('id,oid,payment_time,service_money')->where(['id'=>$order_id])->order('id desc')->find();

        if(empty($order_info)){
            $this->ajaxReturn(1,'订单不存在');
        }
        $total=0;
        $res=[];
        // var_dump($jie_order_info);die;
        if($jie_order_info){

            foreach ($jie_order_info as $k=>$v){
                $oid=$v['id'];
                //查询接单消息
                $res=M('guwen_money_log')->field('lu_uid,ruzhi_type,all_money as money,id,add_time')->where(['order_id'=>$oid,'comp_uid'=>C('visitor.uid')])->select();

                // var_dump(M('guwen_money_log')->getLastSql());die;
                //查询接单的录用用户
                $tui_users=M('guwen_tui_jian_rusume')->where(['order_id'=>$oid,'tui_status'=>['in',[1,3,4]]])->getField('resume_uid',true);
                //   var_dump(M('guwen_money_log')->getLastSql());

                if($tui_users){
//                       $user_names=M('resume')->where(['uid'=>['in',$tui_users]])->getField('fullname',true);
//                       $name_str=implode(',',$user_names);
                    foreach ($res as $k1=>$v1){
//                   if($k==0){
//                       $res[$k]['desc']='入职扣费：'.$v['money'];
//                   }
//                   if($k==1){
//                       $res[$k]['desc']='入职满月扣费：'.$v['money'];
//                   }

                        $user_names=M('resume')->where(['uid'=>$v1['lu_uid']])->getField('fullname');
                        if($v1['ruzhi_type']==1){
                            $arr['desc']='入职扣费';
                        }else{
                            $arr['desc']='入职满月扣费';
                        }
                        //  $arr['desc']='入职扣费：';
                        $arr['add_time']=date('Y-m-d H:i:s',$v['add_time']);
                        $arr['name']=$user_names;
                        $arr['money']=$v1['money'];
                        $arr['id']=$v1['id'];
//                           $res[$k]['desc']='入职扣费：'.$v['money'];
//                           $res[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
//                           $res[$k]['name']=$name_str;
                        $total+=$v1['money'];
                        $list[]=$arr;
                    }
                }
            }


        }
        if($jie_order_info['fa_type']==4){
            $all_sever_money=M('guwen_tui_jian_rusume')->where(['order_id'=>$oid,'tui_status'=>['in',[1,3,4]]])->sum('server_money');
            $order_info['service_money']=$all_sever_money?$all_sever_money:0;
        }

//        $jie_order_info=M('gu_wen_jie_dan_order')->where(['id'=>$oid])->find();
        $order_info['yixiao_money']=$total;
        $order_info['sheng_money']=$order_info['service_money']-$total;
        $order_info['payment_time']=date('Y-m-d H:i:s',$order_info['payment_time']);
        $data['list']=$list;
        $data['info']=$order_info;

        $this->ajaxReturn(0,'ok',$data);
    }

    /**
     * 工程币支付验证码验证
     */

      public function gc_bi_check_pay()
      {
          $mobile = I('mobile', 0);
          $fa_type=I('fa_type',0);
          $type=I('order_type',0); //16 发布职位  1 套餐
//          if (!S('mgcb_' . $mobile)) {
//              $this->ajaxReturn(1, '验证码不存在或已过期');
//          }
          if(!in_array($type,[1,16,14,-1,-2])){
              $this->ajaxReturn(1,'订单类型错误');
          }
          if($type==16){
              if(!I('code',0)){
                  $this->ajaxReturn(1, '验证码不存在或已过期11');
              }
              if (S('mgcb_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
                  $this->ajaxReturn(1, '验证码不存在或已过期');
              }
              S('mgcb_' . $mobile, null);
              $order_id=I('order_id',0);
              if(!$order_id){
                  $this->ajaxReturn(1,'订单不存在');
              }
              $order=M('order')->where(['id'=>$order_id])->find();
              // $order['fa_type']=$fa_type;
              $res = D('Order')->order_paid($order['oid'], NOW_TIME);
              if ($res) {
                  D('Order')->where(array('id' => $order['uid']))->save([
                      //  'all_total'=>['exp','all_total+'.$order['pay_amount']],
                      'fa_type'=>$fa_type
                  ]);
                  //  M('order')->where(['id'=>$order_id])->setField('fa_type',$fa_type);
                  D('MembersSetgcb')->where(['uid' => $order['uid']])->setInc('use_num', $order['pay_amount']);
                //  var_dump($order);die;
                  M('jobs')->where(['id' => $order['jobs_id']])->setField('fa_type', $order['fa_type']);
                  M('jobs_search')->where(['id' => $order['jobs_id']])->setField('fa_type', $order['fa_type']);
                  $this->edit_zhao_type_id($order['fa_type'], $order['jobs_id'], $order['id'], $order['service_money']);
                  //修改发布类型   减少发布次数
                //  var_dump(D('JobsInfo'));die;
                 // var_dump(333);die;
                 JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'gcb','发布职位',date('Y-m-d H:i:s',$order['payment_time']),'fa_bu');
                  $this->ajaxReturn(0, '发布成功',$order_id);
              }
          }elseif($type==1){
              if(!I('code',0)){
                  $this->ajaxReturn(1, '验证码不存在或已过期12');
              }
              if (S('mgcb_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
                  $this->ajaxReturn(1, '验证码不存在或已过期');
              }
              S('mgcb_' . $mobile, null);
              $order_id=I('order_id',0);
              if(!$order_id){
                  $this->ajaxReturn(1,'订单不存在');
              }
              $order=M('order')->where(['id'=>$order_id])->find();
              // $order['fa_type']=$fa_type;
              $res = D('Order')->order_paid($order['oid'], NOW_TIME);
              if ($res) {
                  D('MembersSetgcb')->where(['uid' => $order['uid']])->setInc('use_num', $order['pay_amount']);
                  //修改发布类型   减少发布次数
                  //添加工程币的使用记录
                  //用户记录
                  $user_taocan=D('MembersSettaocan')->get_user_setmeal($order['uid']);
                  add_member_log(C('visitor.uid'), 'gcb', 'resume_down', $order['pay_amount'], 0, '购买套餐'.'【'.$user_taocan['setmeal_name'].'】',0,$user_taocan['settaocan_id']);
                  JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'gcb','购买套餐',date('Y-m-d H:i:s',$order['payment_time']),'buy_taocan');
                  $this->ajaxReturn(0, '支付成功',$order_id);
              }
          }elseif($type==14){
              //简历下载
              if(!I('code',0)){
                  $this->ajaxReturn(1, '验证码不存在或已过期12');
              }
              if (S('mgcb_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
                  $this->ajaxReturn(1, '验证码不存在或已过期');
              }
              S('mgcb_' . $mobile, null);
              $order_id=I('order_id',0);
              if(!$order_id){
                  $this->ajaxReturn(1,'订单不存在');
              }
              $order=M('order')->where(['id'=>$order_id])->find();
              $user_info=M('resume')->where(['id'=>$order['rid']])->find();
               $res = D('Order')->order_paid($order['oid'], time());
             //  var_dump($res);die;
              if ($res===true || $res['state']!=0) {
                            //先修改这个用户的推荐表的订单状态 /0 未接单 1. 已接单 6 待处理 2 处理中 3已完成 4 已取消 5 意向
                     $this->sel_down_user_order($user_info['uid']);
                     JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'gcb','下载简历',date('Y-m-d H:i:s',$order['payment_time']),'down_resume');
                  $res = D('Resume')->save_as_doc_word($order['rid'], '', C('visitor'), 1,1);
                  $site_url = M('config')->where(['name' => 'site_domain'])->find();
                  $url = $site_url['value'] . $res['path'] . $res['name'];
                  //  var_dump($res);
                  $data['url']=$url;
                  $this->ajaxReturn(0, '下载成功！',$data);
                        } else {
                            $this->ajaxReturn(1, $res['msg']);
                        }
          }elseif ($type==-1){
              //顾问主动推荐录取用户工程币支付
              if(!I('code',0)){
                  $this->ajaxReturn(1, '验证码不存在或已过期12');
              }
              if (S('mgcb_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
                  $this->ajaxReturn(1, '验证码不存在或已过期');
              }
              S('mgcb_' . $mobile, null);
              $order_id=I('order_id',0);
              if(!$order_id){
                  $this->ajaxReturn(1,'订单不存在');
              }
              $order=M('lu_yong_pay_order')->where(['id'=>$order_id])->find();
              $res=D('Order')->guwen_zhutui_luyong_orderpaid($order['oid'],time());
            if($res){
               $this->ajaxReturn(0, '支付成功',$order_id);
            }else{
               $this->ajaxReturn(1, '支付失败');
            }
          }elseif ($type==-2){
              //补交支付
              if(!I('code',0)){
                  $this->ajaxReturn(1, '验证码不存在或已过期12');
              }
              if (S('mgcb_' . $mobile) != I('code', 0, 'intval') && I('code', 0, 'intval') != 123456) {
                  $this->ajaxReturn(1, '验证码不存在或已过期');
              }
              S('mgcb_' . $mobile, null);
              $order_id=I('order_id',0);
              if(!$order_id){
                  $this->ajaxReturn(1,'订单不存在');
              }
              $order=M('com_bu_jiao_order')->where(['id'=>$order_id])->find();
              $res=D('Order')->com_bu_jiao_orderpaid($order['oid'],time());
              if($res){
                  $this->ajaxReturn(0, '支付成功',$order_id);
              }else{
                  $this->ajaxReturn(1, '支付失败');
              }
          }

      }


    public function edit_zhao_type_id_copy($type=2, $jobs_id=113, $order_id=316, $service_money=600)
    {

        if ($type == 3) {
            $setsqlarr=M('jobs')->where(['id'=>$jobs_id])->find();
            $setsqlarr['zhao_type_id']=5;
            $setsqlarr['zhao_type_name']='悬赏职位';
            $setsqlarr['id']=$jobs_id;

           $setsqlarr['topclass']=explode(',',$setsqlarr['topclass']);
           $setsqlarr['category']=explode(',',$setsqlarr['category']);
            $city_info=explode('.',$setsqlarr['district']);
          //  var_dump($city_info);
            $setsqlarr['district']=$city_info[2];

            $rst = D('Jobs')->edit_jobs($setsqlarr, C('visitor'));
//            M('jobs')->where(['id' => $jobs_id])->save([
//                'zhao_type_id' => 5,
//                'zhao_type_name' => '悬赏职位',
//            ]);
//
//            M('jobs_search')->where(['id' => $jobs_id])->save([
//                'zhao_type_id' => 5,
//            ]);
        }elseif ($type==2){
            $setsqlarr=M('jobs')->where(['id'=>$jobs_id])->find();
            $setsqlarr['zhao_type_id']=6;
            $setsqlarr['zhao_type_name']='通过顾问职位';
            $setsqlarr['id']=$jobs_id;
            $setsqlarr['topclass']=explode(',',$setsqlarr['topclass']);
            $setsqlarr['category']=explode(',',$setsqlarr['category']);
            $city_info=explode('.',$setsqlarr['district']);
            //  var_dump($city_info);
            $setsqlarr['district']=$city_info[2];
            $rst = D('Jobs')->edit_jobs($setsqlarr, C('visitor'));
//            M('jobs')->where(['id' => $jobs_id])->save([
//                'zhao_type_id' => 6,
//                'zhao_type_name' => '通过顾问职位',
//            ]);
//            M('jobs_search')->where(['id' => $jobs_id])->save([
//                'zhao_type_id' => 5,
//            ]);
        }
        M('order')->where(['id' => $order_id])->setField('service_money', $service_money);
        return true;
    }



    public function sel_res_user()
    {
        $list=M('resume_search_precise')->select();
        foreach ($list as $k=>$v){
            $utype=M('members')->where(['uid'=>$v['uid']])->getField('utype');
            M('resume_search_precise')->where(['id'=>$v['id']])->setField('utype',$utype);
        }
    }



    public function check_has_mang_guwen()
    {
        $ids = I('ids', 0);
        $jobs_id = I('jobs_id', 0);
        $order_id = I('order_id', 0);
        $job_info = M('jobs')->where(['id' => $jobs_id])->find();
        if (empty($job_info)) {
            $this->ajaxReturn(1, '职位不存在');
        }
        $order_info = M('order')->where(['id' => $order_id])->find();
        if (empty($order_info)) {
            $this->ajaxReturn(1, '订单不存在');
        }
        $ids_arr = explode(',', $ids);
        if (count($ids_arr) > 3) {
            $this->ajaxReturn(1, '顾问最多选择三人');
        }
        $count= M('jobs_add_gu_wen')->where([
            'jobs_id' => $jobs_id,
            'com_uid' => C('visitor.uid')
        ])->count();
        if(($count+count($ids_arr)) > 3){
            $this->ajaxReturn(1, '顾问最多选择三人');
        }
        $ids_arr = array_unique($ids_arr);

    }

    /**
     * 预览职位数据
     * @return array
     */
    public function yu_lan_jobs_save()
    {
//
//
//
//        $ids='289';
//        $arr=explode(',',$ids);
//        foreach ($arr as $k=>$v){
//            $res=  get_city_info($v);
//            var_dump($res);
//        }
//        die;
        $data_arr=$_POST;
        $data = JobsInfoModel::check_fabu_params();
        if ($data['status']) {
            $this->ajaxReturn(1, $data['msg']);
        }

        $data=$data['data'];
        $category = D('Category')->get_category_cache();
        $jobs_cates = D('CategoryJobs')->get_jobs_cache('all');
        $data['nature_cn'] = $category['QS_jobs_nature'][$data['nature']];
        $data['education_cn']= $data['education'] == 0 ? '不限' : $category['QS_education'][$data['education']];
        $data['experience_cn'] = $data['experience'] == 0 ? '不限' : $category['QS_experience'][$data['experience']];

        $city =get_city_info($data['district']);
        $data['district'] = $data['district'] = $city['district'];
        $data['district_cn'] = $data['district_cn'] = $city['district_cn_all'];
        $data['age'] = $data['minage'] . "-" . $data['maxage'];
        $sex = array('0' => '不限', '1' => '男', '2' => '女', '3' => '不限');
        $data['sex_cn'] = $sex[$data['sex']];
        $data['display']=1;
        $data['user_status']=1;
        //招聘类型 2020/12/18
        $data['zhao_type_name']=M('category_pin')->where(['id'=>$data['zhao_type_id']])->getField('categoryname');
        $data['topclass']=implode(',',$data['topclass']);
        $data['category']=implode(',',$data['category']);
        //获取企业 信息
        $com_info=M('company_profile')->field('scale,scale_cn')->where(['uid'=>$data['uid']])->find();
        $data['scale']=$com_info['scale'];
        $data['scale_cn']=$com_info['scale_cn'];
        //   var_dump($data);die;
        foreach (explode(',', $data['tag']) as $val) {
            $tag_cn[] = $category['QS_jobtag'][$val];
        }
        $_top_class=explode(',',$data['topclass']);
        // var_dump(explode(',', $data['category']));die;
        foreach (explode(',', $data['category']) as $k=> $val){
            if($val>0){
                $category_cn[] =$jobs_cates[$_top_class[$k]][$val];
            }else{
                $category_cn[] =$jobs_cates[0][$_top_class[$k]];
            }
        }
//            var_dump($category_cn);
//            die;
        //  var_dump($category_cn);die;
//            $tag_classify_class = new \Common\qscmstag\classifyTag(array('列表名'=>'trade_list','类型'=>'QS_trade','显示数目'=>'100','cache'=>'0','type'=>'run',));
//            $trade_list = $tag_classify_class->run();
//
        $trade_list=   D('CategoryMajor')->get_major_list();
        $top_trade=explode(',', $data['top_trade']);
        foreach (explode(',', $data['trade']) as $k=> $val){
            if($val>0){
                $trade_cn[] =$trade_list[$val]['categoryname'];
            }else{
                $trade_cn[] =$trade_list[$top_trade[$k]]['categoryname'];
            }
        }
        $data['trade_cn']=implode(',',$trade_cn);
        $data['category_cn']=implode(',',$category_cn);
        //  $data['tag_cn'] = implode(',', $tag_cn);
        if($data['zi_dy_fl']){
            $zd_tags=explode(',',$data['zi_dy_fl']);
            $tag_cn=array_merge($tag_cn,$zd_tags);
        }
        $data['tag_cn'] =$tag_cn;
        $data['refreshtime_cn']=date('Y-m-d H:i:s');
        $row = '';
        foreach ($data['topclass'] as $k => $v) {
            $row .= $v . '-' . $data['category'][$k] . ',';
        }
        if($data['fa_bu_ids']){
            $ids_arr=explode(',',$data['fa_bu_ids']);
            $data['fa_bu_info']=M('category_district')->where(['id'=>['in',$ids_arr]])->field('id,categoryname')->select();
        }
        $info=$data;
        if ($row) {
            $row = substr($row, 0, strlen($row) - 1);
        }
        $cate_ids=explode(',',$info['category']);
        $top_ids=explode(',',$info['topclass']);
        $trade_ids=explode(',',$info['trade']);
        $top_trade_ids=explode(',',$info['top_trade']);
        foreach ($top_ids as $k=>$v){
            $cates_id.=$v.'-'.$cate_ids[$k].',';
        }
        foreach ($top_trade_ids as $k=>$v){
            $trades_id.=$v.'-'.$trade_ids[$k].',';
        }
        $trade_ids=substr($trades_id,0,strlen($trades_id)-1);
        $cate_ids=substr($cates_id,0,strlen($cates_id)-1);
        $info['job_cate_id']=$cate_ids;
        $info['trade_id']=$trade_ids;
        $wage_info = D('Category')->category_wage();
        $info['wage_cn'] = $wage_info[$info['wage_id']] . 'k';
        $dao_gang_info = D('Category')->category_dao_gang_api();
        // var_dump($dao_gang_info);die;
        $info['zhao_type_id']=$data['zhao_type'];
        $info['zhao_type_name']=M('category_pin')->where(['id'=>$info['zhao_type']])->getField('categoryname');
        $info['dao_gang_cn'] = $dao_gang_info[$info['dao_gang_id']];
        $work_time_info = D('Category')->category_work_time_api();
        $info['work_time_cn'] = $work_time_info[$info['work_time_id']];
        $city_info=explode('.',$info['city_id']);
        $info['city_id']=$city_info[2];
        if (in_array($info['zhao_type_id'], [3, 4])) {
            $info['zhao_cn'] = '项目短期岗位';
        } else {
            $info['zhao_cn'] = '固定岗位';
        }
        $dao_time_info = D('Category')->category_dao_time();
        if ($info['dao_gang_id']) {
            $info['dao_gang_cn'] = $dao_time_info[$info['dao_gang_id']];
        }
        $profile = M('CompanyProfile')->where(array('uid' => C("visitor.uid")))->find();
        $info['company'] = $profile;
        if ($info['company']['logo']) {
            $info['company']['logo'] = attach($info['company']['logo'], 'company_logo');
        } else {
            $info['company']['logo'] = attach('no_logo.png', 'resource');
        }

        $list['info']=$info;
        $list['data']=$data_arr;
        $this->ajaxReturn(0, '', $list);

        //   $r =M('jobs_yu_lan')->add($data);
        return $data;
        // }
    }

    /**
     * 保存职位模板
     */
         public function save_job_tpl()
      {
            $data = JobsInfoModel::check_fabu_params();
            if ($data['status']) {
                $this->ajaxReturn(1, $data['msg']);
            }
            $data=$data['data'];
            $data['tpl_name']=I('tpl_name','');
            $row=M('jobs_tpl_data')->where(['tpl_name'=>$data['tpl_name']])->find();
            if($row){
                $this->ajaxReturn(1,'模板名称已存在');
            }
            if(empty($data['tpl_name'])){
                $this->ajaxReturn(1,'请填写职位模板名称');
            }
            $category = D('Category')->get_category_cache();
            $jobs_cates = D('CategoryJobs')->get_jobs_cache('all');
            $data['nature_cn'] = $category['QS_jobs_nature'][$data['nature']];
            $data['education_cn']= $data['education'] == 0 ? '不限' : $category['QS_education'][$data['education']];
            $data['experience_cn'] = $data['experience'] == 0 ? '不限' : $category['QS_experience'][$data['experience']];
            //  $this->category_cn = $this->subclass ? $jobs_cates[$this->category][$this->subclass] : $jobs_cates[$this->topclass][$this->category];

            $city =get_city_info( $data['district']);
            $data['district'] = $data['district'] = $city['district'];
            $data['district_cn'] = $data['district_cn'] = $city['district_cn_all'];
            $data['age'] = $data['minage'] . "-" . $data['maxage'];
            $sex = array('0' => '不限', '1' => '男', '2' => '女', '3' => '不限');
            $data['sex_cn'] = $sex[$data['sex']];
            $data['display']=1;
            $data['user_status']=1;
            //招聘类型 2020/12/18
            $data['zhao_type_name']=M('category_pin')->where(['id'=>$data['zhao_type_id']])->getField('categoryname');
            $data['topclass']=implode(',',$data['topclass']);
            $data['category']=implode(',',$data['category']);
            //获取企业 信息
            $data['companyname'] =M('company_profile')->where(['uid'=>C('visitor.uid')])->getField('companyname');

            $com_info=M('company_profile')->where(['uid'=>$data['uid']])->find();
            $data['scale']=$com_info['scale'];
            $data['scale_cn']=$com_info['scale_cn'];
            $data['setmeal_id'] = $com_info['setmeal_id'];
            $data['setmeal_name'] = $com_info['setmeal_name'];
            $data['uid'] = C('visitor.uid');
            $data['company_id'] = $com_info['id'];
            $data['company_addtime'] = $com_info['addtime'];
            $data['companyname'] = $com_info['companyname'];
            $data['company_audit'] = $com_info['audit'];
            //   var_dump( $this->category);die;
            foreach (explode(',', $data['tag']) as $val) {
                $tag_cn[] = $category['QS_jobtag'][$val];
            }
            $_top_class=explode(',',$data['topclass']);
            foreach (explode(',', $data['category']) as $k=> $val){
                $category_cn[] =$jobs_cates[$_top_class[$k]][$val];
            }
//            $tag_classify_class = new \Common\qscmstag\classifyTag(array('列表名'=>'trade_list','类型'=>'QS_trade','显示数目'=>'100','cache'=>'0','type'=>'run',));
//            $trade_list = $tag_classify_class->run();
//
             $trade_list=   D('CategoryMajor')->get_major_list();
            foreach (explode(',', $data['trade']) as $k=> $val){
                $trade_cn[] =$trade_list[$val]['categoryname'];
            }
            $data['trade_cn']=implode(',',$trade_cn);
            $data['category_cn']=implode(',',$category_cn);
            $data['tag_cn'] = implode(',', $tag_cn);
             //var_dump($data);die;
           $insert_id = M('jobs_tpl_data')->add($data);
           if($insert_id){
               $this->ajaxReturn(0,'操作成功');
           }else{
               $this->ajaxReturn(1,'操作失败,请重试');
           }
        }

    /**
     * 修改企业的隐私
     */
      public function com_dis()
      {
          // $username = "zongzi22";
         // echo substr_replace($username,'****','2','4');die;
         $display= I('display',2);  // 1 展示 2 隐藏
         M('company_profile')->where(['uid'=>C('visitor.uid')])->setField('display',$display);
         $this->ajaxREturn(0,'操作成功');
      }

    /**
     * 顾问主动推荐订单录用支付
     */
       public function lu_yong_pay()
       {
           $uid=I('uid',0);
           $jie_order_id=I('jie_order_id',0);
           $jobs_id=I('jobs_id',0);
           $status=I('status',0);
           if(!in_array($status,[1,2,3,4])){
               $this->ajaxReturn(1,'状态错误');
           }
           $payment_name=I('payment_name','');
           if(!$payment_name){
            $this->ajaxReturn(1,'请选择支付方式');
           }
           $ruzhi_time= I('ruzhi_time','');
           !$uid && $this->ajaxReturn(1,'用户不存在');
           $order_info=M('guwen_tui_jian_rusume')->where(['resume_uid'=>$uid,'order_id'=>$jie_order_id,'jobs_id'=>$jobs_id])->find();
           if(empty($order_info)){
               $this->ajaxReturn(1,'订单不存在');
           }
           if($order_info['tui_status']>2){
               $this->ajaxReturn(1,'职位订单已处理');
           }
           // todo 判断录用人数与 发布职位的招聘人数
           //判断是不是主动推荐人才   是的话就先支付   否则就直接转账
           $jie_dan_info=M('gu_wen_jie_dan_order')->where(['id'=>$jie_order_id])->find();
           if(empty($jie_dan_info)){
               $this->ajaxReturn(1,'接单信息不存在');
           }
           //判断订单是否停止
           $jobs_order=M('order')->where(['jobs_id'=>$jobs_id])->find();
           if($jobs_order['is_stop']){
               $this->ajaxReturn(1,'订单已停止');
           }
//           $res=check_is_can_tui($jobs_id,$jie_dan_info['comp_uid'],$jie_dan_info['fa_bu_order'],$uid);
//           if(!$res){
//               $this->ajaxReturn(1,'录用人数已满');
//           }
           if($jie_dan_info['fa_type']!=4){
               $this->ajaxReturn(1,'订单类型错误');
           }

           $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
            $desc='推荐的人才';
           if($status==1 && empty($ruzhi_time)){
               $this->ajaxReturn(1,'请选择入职时间');
           }
           if($order_info['tui_status']==0 && $status==1){//入职
               //增加顾问余额记录
               $money_info=$this->get_job_in_money($order_info['gw_uid'],$jobs_info,1,$order_info['server_money'],$order_info['xishu_rate']);
           }
           if($order_info['tui_status']==1 && $status==4){  //入职满月
               //增加顾问余额记录
               $money_info=$this->get_job_in_money($order_info['gw_uid'],$jobs_info,2,$order_info['server_money'],$order_info['xishu_rate']);
           }

       // var_dump($money_info);die;
           if ($payment_name == 'gcb') {
               $gcb_info = D('MembersSetgcb')->get_user_setmeal(C('visitor.uid'));
               if (empty($gcb_info)) {
                   $this->ajaxReturn(1, '您目前没有工程币套餐');
               }
               if ($gcb_info['all_num'] - $gcb_info['use_num'] < $money_info['all_money']) {
                   $this->ajaxReturn(1, '您的工程币余额不足');
               }
               //生成一个订单
               $oid = "GRZ-" . date('ymd', time()) . "-" . date('His', time()); //订单号
               $order_insert_id = $this->add_lu_yong_order_log($uid,$jie_dan_info['id'],$jie_dan_info['comp_uid'],$oid,$money_info['all_money'],'gcb','工程币支付',$status,$ruzhi_time,$jobs_id);
               write_members_log(C('visitor'), 'lu_yorder', '录用推荐用户订单（订单号：' . $oid . '），支付方式：工程币支付', false, array('order_id' => $order_insert_id));
               $this->ajaxReturn(0, '操作成功', $order_insert_id);
           } elseif ($payment_name == 'remittance') {
               //线下转账
               //生成一个订单
           $oid = "RRZ-" . date('ymd', time()) . "-" . date('His', time()); //订单号
           $order_insert_id = $this->add_lu_yong_order_log($uid,$jie_dan_info['id'],$jie_dan_info['comp_uid'],$oid,$money_info['all_money'],'remittance','线下支付',$status,$ruzhi_time,$jobs_id);
           write_members_log(C('visitor'), 'lu_yorder', '录用推荐用户订单（订单号：' . $oid . '），支付方式：线下转账支付', false, array('order_id' => $order_insert_id));
            if ($order_insert_id) {
                   $this->ajaxReturn(0, '成功，请等待管理员审核', $order_insert_id);
            } else {
                   $this->ajaxReturn(1, '下单出错');
            }

           }  else {
               //微信
               $oid = "WRZ-" . date('ymd', time()) . "-" . date('His', time()); //订单号
               $order_insert_id = $this->add_lu_yong_order_log($uid,$jie_dan_info['id'],$jie_dan_info['comp_uid'],$oid,$money_info['all_money'],'wxpay','微信支付',$status,$ruzhi_time,$jobs_id);
               write_members_log(C('visitor'), 'lu_yorder', '录用推荐用户订单（订单号：' . $oid . '），支付方式：微信支付', false, array('order_id' => $order_insert_id));
               $wxcode         = I('post.wxcode','','trim,badword');
//               if (empty($wxcode)) $this->ajaxReturn(1, '微信wxcode不能为空');
//               $openId     = wxOpenId($wxcode, $this->userinfo['uid']);
//               if (!empty($openId['status'])) $this->ajaxReturn(1, '微信openId获取失败');
               $paysetarr['payFrom'] = 'pc';
               $paysetarr['type'] = 'wxpay';
               $paysetarr['ordsubject'] = '录用支付';
               $paysetarr['ordbody'] = '录用支付';
            //   $paysetarr['openid'] = $openId['data'];
               $paysetarr['action']='lu_yong_pay';
               $paysetarr['oid']   =$oid;
               $paysetarr['ordtotal_fee']=$money_info['all_money'];
               $r = D('Payment')->wx_pay($paysetarr);
             //  var_dump($r);die;
               if(!$r['state']) return ['status'=> 1, 'msg'=>$r['msg']];
               $url=$r['data'];
               $str=$this->indexBase64($url);
               $r['img_base']=$str;
               $r['insert_id']    = $order_insert_id;

             //  var_dump($r);die;
               $this->ajaxReturn(0, 'ok', $r);
           }
//           $re=  M('guwen_tui_jian_rusume')->where(['id'=>$order_info['id']])->save([
//               'tui_status'=>$status,
//               'up_time'=>date('Y-m-d H:i:s',time()),
//               'ruzhi_time'=>$ruzhi_time,
//           ]);
//           M('gu_wen_jie_dan_order')->where(['id'=>$jie_order_id])->setField('order_status',3);
//           !$re && $this->ajaxReturn(1,'操作失败');
//           $this->ajaxReturn(0,'操作成功');
       }

    /**
     * 添加顾问主动推荐人才 企业录用 订单
     * @param $uid      录用用户ID
     * @param $order_id   接单ID
     * @param $comp_uid   企业用户ID
     * @param $oid       订单编号
     * @param $money       金额
     * @param $payment      支付方式
     * @param $payment_cn   支付名称
     * @param $tui_status   录用状态
     * @param $ruzhi_time  入职时间
     * @param $jobs_id    职位ID
     * @return mixed
     */
       public function add_lu_yong_order_log($uid,$order_id,$comp_uid,$oid,$money,$payment,$payment_cn,$tui_status,$ruzhi_time,$jobs_id)
       {
         $res=  M('lu_yong_pay_order')->add([
            'uid'=>$uid,
            'jie_order_id'=>$order_id,
            'comp_uid'=>$comp_uid,
            'pay_status'=>0,
             'pay_time'=>0,
             'oid'=>$oid,
             'add_time'=>NOW_TIME,
             'pay_money'=>$money,
             'payment'=>$payment,
             'payment_cn'=>$payment_cn,
             'tui_status'=>$tui_status,
             'ruzhi_time'=>$ruzhi_time,
             'jobs_id'=>$jobs_id
           ]);
        return $res;

       }

    /**
     * 查询是否可以去推送
     * @param $jobs_id
     * @param $comp_uid
     * @param $order_id
     * @return int
     */
       public function check_is_can_tui()//$jobs_id,$comp_uid,$order_id
       {
           $jobs_id=4;
           $comp_uid=4;
           $order_id=8;
           //判断是否显示可以去投建简历
           //查询职位的招聘人数
           $jobs_info=M('jobs')->where(['id'=>$jobs_id])->find();
           //判断已经录用的人数
           $jie_order_ids=M('gu_wen_jie_dan_order')->where(['jobs_id'=>$jobs_id,'fa_bu_order'=>$order_id,'comp_uid'=>$comp_uid])->getField('id',true);
           if($jie_order_ids){
               $count=M('guwen_tui_jian_rusume')->where(['jobs_id'=>$jobs_id,
                  'order_id'=>['in',$jie_order_ids],
                   'comp_uid'=>$comp_uid,
                   'tui_status'=>['in',[1,3,4]]
               ])->count();
               $count=$count?$count:0;
//               var_dump($jobs_info['amount']);
//               var_dump($count);die;
               if($count<$jobs_info['amount']){
                   return 1;
               }
               return 0;
           }
           return 1;

       }

    /**
     * /**
     * 添加企业购买 其邀请顾问获得分佣
     * @param $comp_uid
     * @param $order_type
     * @param $order_id
     * @return bool
     */
       public function add_guwen_tui_com_give_money_log($comp_uid,$order_type,$order_id)
       {
           //查询企业用户是不是我推荐的
          //是  判断订单类型  buy_taocan  购买套餐   buy_gcb 购买工程币  fa_bu 微信支付发布职位
//           $comp_uid=11;
//           $order_type='buy_taocan';
//           $order_id=29;
           $order_info=M('order')->where(['id'=>$order_id])->find();
           if(empty($order_info)){
               return true;
           }
           $com_info=M('company_profile')->where(['uid'=>$comp_uid])->find();
           if(empty($com_info)){
               return true;
           }
           $desc="企业【".$com_info['companyname']."】";
           switch ($order_type){
               case 'buy_taocan':
                   $desc.="购买套餐";
                   break;
               case 'buy_gcb':
                   $desc.='购买工程币';
                   break;
               case 'fa_bu':
                  $desc.='发布职位';
           }
          $tui_info=M('guwen_user')->where(['uid'=>$comp_uid])->find();

         //  $money=$order_info['pay_amount']*0.05;
           //var_dump($money);die;
         if($tui_info){
            $money=$order_info['pay_amount']*0.05;
            add_guwen_money($tui_info['guwen_id'],$money,$desc,$order_type,1,0,0,0,0,$order_info['id'],$desc,$comp_uid,$money,2);
            return true;
         }
         return true;
       }

    /**
     * 顾问推荐 企业支付获得金额记录
     */
       public function gw_tui_com_money_log()
       {
           $where['add_type']=2;
           $type=i('type',1);
           $where['type']=$type;
           $page=I('page',1);
           $page_size=I('page_size',10);

           $list=M('guwen_money_log')
                ->join('as gl left join qs_order as o on gl.order_id=o.id ')
               ->field('o.uid,gl.add_time,sum(gl.money) as money,gl.desc,sum(o.pay_amount) as pay_amount')->where($where)->page($page,$page_size)->group('gl.comp_uid')->order('gl.id desc')->select();

           foreach($list as $k=>$v){
               $list[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
               $comp_info=M('company_profile')->field('logo,companyname')->where(['uid'=>$v['uid']])->find();
               $list[$k]['qy_logo']= $comp_info['logo']? attach($comp_info['logo'], 'company_logo'): C('qscms_site_domain') . __ROOT__ . '/data/upload/company_logo/default.png';
               $list[$k]['companyname']=$comp_info['companyname'];
           }
           $count=M('guwen_money_log')->where($where)->count();
           $data['list']=$list;
           $data['total']=$count;
           $this->ajaxREturn(0,'',$data);
       }


    public function dd($dd)
    {

        $a = rand(1, 33);
        if (in_array($a, $dd)) {
            $this->dd($dd);
        } else {
            $dd[] = $a;
        }
        return $dd;
    }
    public function  ass()
    {

        // 2   4   20   22 24   29   16
        // 2  11   13   21  24  26   4
        // 3  12   13   20  22  24   3
        // 4  10   14   16  17  28   7
        //  5   7   10   18  27  28   12
        $arr=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33];
        $data['num']=[];
        $data['value']=[];

        for($z=1;$z<2099;$z++){
            $str='';
            $dd=[];
            for ($i=0;$i<6;$i++){
                $a= rand(1,33);
                if(in_array($a,$dd)){
                    $dd= $this->dd($dd);
                }else{
                    $dd[]=$a;
                }
            }
//    $d=explode(',',$str);
            asort($dd);
            $str=implode(',',$dd);

            // var_dump($str);die;
            $b=  rand(1,16);
            $str.=','.$b;
            // var_dump($a);die;
            if(in_array($str,$data['value'])) {
                $key=array_search($str, $data)  ;
                $data['num'][$key]+=1;
            }else{
                $data['value'][]=$str;
            }
        }
        $shu_ju=[];
        for($i=0;$i<=5;$i++){
            $axxx=array_rand($data['value'],5);
            foreach($axxx as $k=>$v){
                $shu_ju[]=$data['value'][$v];
            }
            // var_dump(array_rand($data['value'],5));
        }
//        var_dump($shu_ju);die;
//        var_dump($data);die;
//        var_dump($str);
//        var_dump($b);die;
    }

     public function change_guwen_level()
     {
         //每年12.31 日修改顾问的等级
         //查询今年是否修改过 没有则修改
         $list = M('members')->where(['utype' => 3])->select();
      //   var_dump($list);
//var_dump(M('members')->getLastSql());die;
        $time= strtotime("+1 year");//返回时间戳, 如果要转换成一般时间格式还需要下面的函数
      $date=date('Y', $time);
     // var_dump($date);
         foreach ($list as $k => $v) {
             //查询当前顾问今年是否修改过
         $row=  M('guwen_level_log')->where(['gw_uid'=>$v['uid'],'has_date'=>$date])->find();
       //  var_dump(M('guwen_level_log')->getLastSql());die;
             if($row){
                  continue;
              }
             //查询当前顾问是否达到了升级的金额
         $info=  M('guwen_level')->where(['level'=>['gt',$v['advisor_level']]])->order('level desc')->select();
           //查询今年 总收入
//var_dump(M('guwen_level')->getLastSql());die;
         $start_time=strtotime(date('Y').'-01-01'.' 00:00:00');
         $end_time=strtotime(date('Y').'-12-31'.' 00:00:00');
         $all_money=  M('guwen_money_log')->where(['type'=>1,'add_time'=>['between',"$start_time,$end_time"],'add_type'=>1,'gw_uid'=>$v['uid']])->sum('money');
         // var_dump( M('guwen_money_log')->getLastSql());die;

             //增加升级记录
        // var_dump(M('guwen_money_log')->getLastSql());
        //     var_dump($all_money);//die;
             $level=0;
             $old_info=M('guwen_level_log')->where(['gw_uid'=>$v['uid']])->order('id asc')->find();
//var_dump(M('guwen_level_log')->getLastSql());die;
             $level=$old_info['level'];
             $level_name=$old_info['level_name'];
         foreach($info as $k1=>$v1){
           if($all_money>$v1['nian_shou']){
              $level=$v1['level'];
              $level_name=$v1['name'];
           }
         }
         if($level==$old_info['level']){
            $level_info= M('guwen_level')->where(['nian_shou'=>['lt',$all_money]])->order('level desc')->find();
       //     var_dump(M('guwen_level')->getLastSql());die;
            if($level_info['advisor_level']>$level){
                $level=$level_info['level'];
                $level_name=$level_info['name'];
            }
         }

             if($level==$old_info['level']){
                 continue;
             }
             //修改等级
           $res=  M('members')->where(['uid'=>$v['uid']])->save([
                 'advisor_level'=>$level,
                 'advisor_level_name'=>$level_name
             ]);
         //    var_dump(M('members')->getLastSql());die;
             if($res){
                 M('guwen_level_log')->add([
                     'gw_uid'=>$v['uid'],
                     'shou_quan_time'=>time(),
                     'has_date'=>$date,
                     'jl_count'=>$v['user_count'],
                     'money'=>$all_money,
                     'level'=>$level,
                     'level_name'=>$level_name,
                 ]);
                 var_dump( M('guwen_level_log')->getLastSql());die;
             }
           //  var_dump($level);//die;
         }

     }

    /**
     * 查询顾问未接单的数量
     */
    public function get_wei_jie_order()
    {
        $uid=C('visitor.uid');
        $count=M('gu_wen_jie_dan_order')->where(['gw_uid'=>$uid,'order_status'=>0])->count();
        $data['count']=$count;
        $this->ajaxREturn(0,'',$data);
    }



    public function axc()
    {
        $list=[];
        $list[0]=M('resume')->where(['id'=>1])->order('id desc')->find();
        $this->assign('list',$list);
        $this->display('Emailtpl/word_resume');
    }

    /**
     * 获取顾问订单的数量
     */

    public function get_gw_order_count()
    {
        //通过顾问
        $guwen_count=M('order')
           ->field('j.district_cn,j.zhao_end_time,j.addres_detail,j.id as jobs_id,j.jobs_name,j.trade_cn,j.category_cn,j.education_cn,j.experience_cn,j.wage_id,o.id,j.addtime')
           ->join('as o right join qs_jobs as j on o.jobs_id=j.id')
           ->where(['o.fa_type'=>2,'o.uid'=>C('visitor.uid')])->count();
       //通过悬赏
        $xuan_shang= M('order')
            ->field('j.district_cn,j.zhao_end_time,j.addres_detail,j.id as jobs_id,j.jobs_name,j.trade_cn,j.category_cn,j.education_cn,j.experience_cn,j.wage_id,o.id,j.addtime')
            ->join('as o right join qs_jobs as j on o.jobs_id=j.id')
            ->where(['o.fa_type'=>3,'o.uid'=>C('visitor.uid')])->count();
        //顾问主动推荐
        $zhutui_shang=M('order')
            ->field('j.district_cn,j.zhao_end_time,j.addres_detail,j.id as jobs_id,j.jobs_name,j.trade_cn,j.category_cn,j.education_cn,j.experience_cn,j.wage_id,o.id,j.addtime')
            ->join('as o right join qs_jobs as j on o.jobs_id=j.id')
            ->where(['o.fa_type'=>4,'o.uid'=>C('visitor.uid')])->count();
        //我的合作
        $where['m.utype']=3;
        //我的合作
        $he_zuo_count = M('gu_wen_jie_dan_order')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,m.username,m.advisor_level as level')
            ->join('as j left join qs_members as m on j.gw_uid=m.uid')
            ->join('right join qs_resume as q on m.uid=q.uid')
            ->where($where)
            ->where(['comp_uid' => C('visitor.uid'),'j.order_status'=>['not in',[0]]])
            ->group('m.uid')->count();
      //我的收藏
        $coll_count= M('gw_collection_comp')->join('as gc left join qs_members as m on gc.gw_uid=m.uid')
            ->join('right join qs_resume as q on m.uid=q.uid')
            ->field('m.user_count,m.uid,m.utype,m.avatars,m.advisor_level_name as levelname,m.username,m.advisor_level as level')
            ->where(['gc.com_uid' => C('visitor.uid')])
            ->where($where)
            ->count();
        $data['guwen_count']=$guwen_count?$guwen_count:0;
        $data['xuan_shang']=$xuan_shang?$xuan_shang:0;
        $data['he_zuo_count']=$he_zuo_count?$he_zuo_count:0;
        $data['coll_count']=$coll_count?$coll_count:0;
        $data['zhutui_count']=$zhutui_shang?$zhutui_shang:0;
        $this->ajaxReturn(0,'ok',$data);
    }


    /**
     * @desc 职位详情
     */
    public function jobs_det_show()
    {
        if (!I('id')) {
            $this->ajaxReturn(1, '职位不存在', '');
        }
        $fa_type=I('fa_type',0);
        //audit 1 认证通过  2 等待认证 3 认证未通过 0 未认证
        $tag_jobs_show_class = new \Common\qscmstag\jobs_showTag(array('列表名' => 'jobs_info','发布类型'=>$fa_type, '职位id' => _I(I('id')), 'cache' => '0', 'type' => 'run',));
        $jobs_info = $tag_jobs_show_class->run();
//      $frontend = new \Common\Controller\FrontendController;
//      $page_seo = $frontend->_config_seo(array("pname"=>"","title"=>"{jobs_name} - {companyname} - {site_name}","keywords"=>"{companyname},{jobs_name},{nature_cn},{category_cn},{district_cn}","description"=>"{companyname}招聘岗位,{jobs_name}","header_title"=>""),$jobs_info);
        $this->ajaxReturn(0, '', $jobs_info);
    }

    public function wx_erwei_pay($order_pay_type,$amount)
    {
        $re = call_web_cash_pay('发布职位', $order_pay_type, '', 'wxpay', $amount, 0, 0, []);
        $url=$re['data']['data'];
        $str=$this->indexBase64($url);
        $this->ajaxReturn(0,'ok',$str);
        //var_dump($re);die;
    }



    /**
     * [indexBase64 跟据传值，生成二维码base64]
     */
    public function indexBase64($url){
        if($url){//echo 111;exit;
            ob_clean();
            $url = htmlspecialchars_decode($url,ENT_QUOTES);
            Vendor('phpqrcode.phpqrcode');
            $qrcode = new \QRcode();
            ob_clean();

            //打开缓冲区
            ob_start();
            //生成二维码图片
            $returnData = $qrcode::pngString($url,false, "H", 3, 1);
            //这里就是把生成的图片流从缓冲区保存到内存对象上，使用base64_encode变成编码字符串，通过json返回给页面。
            $imageString = base64_encode(ob_get_contents());
            //关闭缓冲区
            ob_end_clean();
            $str = "data:image/png;base64,".$imageString;
            return $str;
//            echo $str;exit;
//            $this->ajaxReturn(0, 'ok', $str);
        }
    }

    /**
     * 录用支付验证
     */

    public function check_lu_yong_pay()
    {
        $oid = I('order_id', 0);
        file_put_contents('order_id.txt',$oid);
        !$oid && $this->ajaxReturn(1, '订单不存在');
        $order_info = M('lu_yong_pay_order')->where(['id' => $oid])->find();
        if (empty($order_info)) {
            $this->ajaxReturn(1, '订单信息不存在');
        }
        if ($order_info['pay_status'] == 0) {
            $this->ajaxReturn(1, '订单未支付');
        }

        $this->ajaxReturn(0, '', $order_info);
    }

    /**
     * @desc 公司详情
     * @time 2020/12/17 14：42
     */

    public function com_show()
    {
        //var_dump(111);die;
        $tag_company_show_class = new \Common\qscmstag\company_showTag(array('列表名' => 'info', '企业id' => _I(I('id')), 'cache' => '0', 'type' => 'run',));
        $info = $tag_company_show_class->run();
        $tag_jobs_list_class = new \Common\qscmstag\jobs_listTag(array('列表名' => 'jobs', '会员uid' => $info['uid'], '显示数目' => '20', '排序' => 'stickrtime', '分页显示' => '1', '分站' => '1', 'cache' => '0', 'type' => 'run','职位id'=>I('jobs_id')));
        $info_jobs_list = $tag_jobs_list_class->run();
        $info['list'] = $info_jobs_list['list'];
        $this->ajaxReturn(0, '', $info);
    }


    /**
     * 补交保证金
     * @return array
     */
    public function service_bujiao()
    {
        $order_id=I('order_id');    ///////

        if(!$order_id){
            $this->ajaxReturn(1,'订单错误');
        }
        //   $jie_order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->select();
        $order_info=M('order')->field('jobs_id,id,oid,payment_time,service_money')->where(['id'=>$order_id])->order('id desc')->find();

        if(empty($order_info)){
            $this->ajaxReturn(1,'订单不存在');
        }
        $uid=C('visitor.uid');

        //计算补交金额

        $jie_order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->getField('id',true);

        $res=M('guwen_money_log')->field('lu_uid,ruzhi_type,all_money as money,id,add_time')->where(['order_id'=>['in',$jie_order_info],'comp_uid'=>C('visitor.uid')])->sum('all_money');

        $sheng_money=$order_info['service_money']-$res;
        //  var_dump($sheng_money);die;
        if($sheng_money>0){
            $this->ajaxReturn(1,'不需要补交');
        }

        $payment_name = I('payment_name', '');//wxpay   gcb
        if (empty($payment_name)) {
            $this->ajaxReturn(1, '请选择支付方式');
        }
        $row=M('com_bu_jiao_order')->where([
            'uid'=>$uid,
            'order_id'=>$order_id,
            'jobs_id'=>$order_info['jobs_id']
        ])->find();
        if($row['pay_status']){
            $this->ajaxReturn(1,'订单已支付');
        }
        if($payment_name=='wxpay'){
            $payment_cn='微信支付';
        }elseif ($payment_name=='gcb'){
            $payment_cn='工程币支付';
        }elseif ($payment_name=='remittance'){
            $payment_cn='线下转账';
        }

        if (abs($sheng_money) >= 6000 && $payment_name != 'remittance') {
            $this->ajaxReturn(1, "高于6000请线下付款！");
        }
        //生成顾问的类型订单
        if ($payment_name == 'gcb') {
            $gcb_info = D('MembersSetgcb')->get_user_setmeal(C('visitor.uid'));
            if (empty($gcb_info)) {
                $this->ajaxReturn(1, '您目前没有工程币套餐');
            }
            if ($gcb_info['all_num'] - $gcb_info['use_num'] < abs($sheng_money)) {
                $this->ajaxReturn(1, '您的工程币余额不足');
            }
            //生成一个订单
            $oid = "GRZ-" . date('ymd', time()) . "-" . date('His', time()); //订单号
            $order_insert_id = add_bu_jiao_order_log($uid,$order_id,$oid,abs($sheng_money),'gcb','工程币支付',$order_info['jobs_id']);
            write_members_log(C('visitor'), 'bujiao_yorder', '补交订单（订单号：' . $oid . '），支付方式：工程币支付', false, array('order_id' => $order_insert_id));
            $this->ajaxReturn(0, '操作成功', $order_insert_id);
        } elseif ($payment_name == 'remittance') {
            //线下转账
            //生成一个订单
            $oid = "RRZ-" . date('ymd', time()) . "-" . date('His', time()); //订单号
            $order_insert_id = add_bu_jiao_order_log($uid,$order_id,$oid,abs($sheng_money),'remittance','线下支付',$order_info['jobs_id']);
            write_members_log(C('visitor'), 'bujiao_yorder', '补交订单（订单号：' . $oid . '），支付方式：线下转账支付', false, array('order_id' => $order_insert_id));
            if ($order_insert_id) {
                $this->ajaxReturn(0, '成功，请等待管理员审核', $order_insert_id);
            } else {
                $this->ajaxReturn(1, '下单出错');
            }

        }  else {
            $oid = "WRZ-" . date('ymd', time()) . "-" . date('His', time()); //订单号
            $order_insert_id = add_bu_jiao_order_log($uid,$order_id,$oid,abs($sheng_money),'wxpay','微信支付',$order_info['jobs_id']);
            write_members_log(C('visitor'), 'bujiao_yorder', '补交订单（订单号：' . $oid . '），支付方式：微信支付', false, array('order_id' => $order_insert_id));
            $wxcode         = I('post.wxcode','','trim,badword');
//               if (empty($wxcode)) $this->ajaxReturn(1, '微信wxcode不能为空');
//               $openId     = wxOpenId($wxcode, $this->userinfo['uid']);
//               if (!empty($openId['status'])) $this->ajaxReturn(1, '微信openId获取失败');
            $paysetarr['payFrom'] = 'pc';
            $paysetarr['type'] = 'wxpay';
            $paysetarr['ordsubject'] = '补交支付';
            $paysetarr['ordbody'] = '补交支付';
            //   $paysetarr['openid'] = $openId['data'];
            $paysetarr['action']='bu_jiao_pay';
            $paysetarr['oid']   =$oid;
            $paysetarr['ordtotal_fee']=abs($sheng_money);
            $r = D('Payment')->wx_pay($paysetarr);
          //    var_dump($r);die;
            if(!$r['state']) return ['status'=> 1, 'msg'=>$r['msg']];
            $url=$r['data'];
            $str=$this->indexBase64($url);
            $r['img_base']=$str;
            $r['insert_id']    = $order_insert_id;
            //  var_dump($r);die;
            $this->ajaxReturn(0, 'ok', $r);
        }

    }
    /**
     * 顾问保证金详情
     */
    public function bondItem(){
        $oid = I('order_id');
        $gw_uid = I('gw_uid');
        // 参数选择
        if(!$oid || !$gw_uid){
            $this->ajaxReturn(1,'订单错误');
        }

        //联表查询表
        $log = M('guwen_money_log g')
                ->field('g.id,g.ruzhi_type,g.lu_uid,g.add_time,g.money,g.order_id')
                ->join('left join qs_gu_wen_jie_dan_order as q on q.id=g.order_id')
                ->where(['q.fa_bu_order'=>$oid,'q.gw_uid'=>$gw_uid,'g.order_type'=>'service',])
                ->order('g.add_time DESC')
                ->select();
        //循环处理数据
        $data_log = [];
        $total = 0;
        foreach($log as $v){
            //查询简历人姓名
            if(!$v['lu_uid']){
               
                $guwen_tui_jian_rusume = M('guwen_tui_jian_rusume')->field('resume_uid')->where(['order_id'=>$v['order_id'],'guwen_uid'=>$gw_uid])->find();
                $v['lu_uid'] = $guwen_tui_jian_rusume['resume_uid'];
            }
            $user_names=M('resume')->where(['uid'=>$v['lu_uid']])->getField('fullname');
            //扣费类型
            if($v['ruzhi_type']==1){
                $v['desc']='入职扣费';
            }else{
                $v['desc']='入职满月扣费';
            }
            $v['add_time']=date('Y-m-d H:i:s',$v['add_time']);
            $v['name']=$user_names;
            $v['money']=$v['money'];
            $v['id']=$v['id'];
            $total+=$v['money'];
            $data_log[]=$v;

        }
        $data = [];
        $order = M('order')->field('oid')->find($oid);
        $data['oid'] = $order['oid'];
        $data['yixiao_money'] = $total;
        $data['list'] = $data_log;
        $this->ajaxReturn(0, 'ok',$data);
    }
    /**
     * 保证金详情
     */
    public function bondItemall(){
        $order_id=I('order_id');
        !$order_id && $this->ajaxReturn(1,'订单错误');
        $jie_order_info=M('gu_wen_jie_dan_order')->where(['fa_bu_order'=>$order_id])->select();
        $data=M('order')->field('id,oid,payment_time,service_money')->where(['id'=>$order_id])->order('id desc')->find();
        if(empty($data)){
            $this->ajaxReturn(1,'订单不存在');
        }
        $total=0;
        $info = [];
        if($jie_order_info){
            foreach ($jie_order_info as $k=>$v){
              
                $infoitem['fullname'] =  M('resume')->where(['uid'=>$v['gw_uid']])->getField('fullname');
                
                $oid=$v['id'];
                //查询接单消息
                $res=M('guwen_money_log')->field('lu_uid,ruzhi_type,all_money as money,id,add_time')->where(['order_id'=>$oid,'comp_uid'=>C('visitor.uid')])->select();
                //查询接单的录用用户
                $tui_users=M('guwen_tui_jian_rusume')->where(['order_id'=>$oid,'tui_status'=>['in',[1,3,4]]])->getField('resume_uid',true);
                if($tui_users){
                    $infoitem['list'] = [];
                    if($res){
                        
                        foreach ($res as $k1=>$v1){
                            $arr = [];
                            //查询简历人姓名
                            if(!$v1['lu_uid']){
                                $v1['lu_uid'] = $tui_users[0];
                            }
                            if($v1['ruzhi_type']==1){
                                $arr['desc']='入职扣费';
                            }else{
                                $arr['desc']='入职满月扣费';
                            }
                            $arr['add_time']=date('Y-m-d H:i:s',$v['add_time']);
                            $arr['name']=M('resume')->where(['uid'=>$v1['lu_uid']])->getField('fullname');;
                            $arr['money']=$v1['money'];
                            $arr['id']=$v1['id'];
                            
                            $total+=$v1['money']; 
                            $infoitem['list'][]=$arr;
                        }
                    }else{
                        $arr['desc']= '' ;
                        $arr['add_time'] = '';
                        $arr['name'] = '';
                        $arr['money']= '';
                        $arr['id']= 0 ;
                        $infoitem['list'][]=$arr;
                    }
                    
                    $info[]=$infoitem;
                }
            }


        }
        if($jie_order_info['fa_type']==4){
            $all_sever_money=M('guwen_tui_jian_rusume')->where(['order_id'=>$oid,'tui_status'=>['in',[1,3,4]]])->sum('server_money');
            $data['service_money']=$all_sever_money?$all_sever_money:0;
        }
        //审核状态
        $order_info=M('com_bu_jiao_order')->where(['order_id'=>$order_id])->find();
        if($order_info['pay_status']){
            $data['pay_status']=1;
        }else{
            if(empty($order_info)){
                $data['pay_status']=-1;
            }else{
                $data['pay_status']=0;
            }
        }

        $data['yixiao_money']=$total;
        $data['sheng_money']=$data['service_money']-$total;
        $data['payment_time']=date('Y-m-d H:i:s',$data['payment_time']);
        $data['info']=$info;
        

        $this->ajaxReturn(0,'ok',$data);
    }

    /**
     * 补交支付验证
     */

    public function check_bu_jiao_pay()
    {
        $oid = I('order_id', 0);
        file_put_contents('order_id.txt',$oid);
        !$oid && $this->ajaxReturn(1, '订单不存在');
        $order_info = M('com_bu_jiao_order')->where(['id' => $oid])->find();
        if (empty($order_info)) {
            $this->ajaxReturn(1, '订单信息不存在');
        }
        if ($order_info['pay_status'] == 0) {
            $this->ajaxReturn(1, '订单未支付');
        }

        $this->ajaxReturn(0, '', $order_info);
    }
    /**
     * 停止订单
     */
    public function change_is_stop()
    {
        $order_id=I('order_id',0);
        $order_info=M('order')->where(['id'=>$order_id])->find();
        if(!$order_id || empty($order_info)){
            $this->ajaxReturn(1,'订单不存在');
        }
        $res=check_is_chu($order_info['jobs_id']);
        if(!$res){
          $this->ajaxReturn(1,'您还有未处理的订单');
        }

      if($order_info['is_stop']){
         $this->ajaxReturn(1,'此订单已结束');
      }
      $re=M('order')->where(['id'=>$order_id])->setField('is_stop',1);
      if($re){
          $this->ajaxReturn(0,'设置成功');
      }else{
          $this->ajaxReturn(1,'请求出错，请重试');
      }

    }


}